Create a Timestamp without timeZone(创建没有 timeZone 的时间戳)
问题描述
如何创建没有时区的 java.sql.timestamp
(我得到 2007-09-23T10:10:10Z
并且我假装 2007-09-23T10:10:10
).
How can I create a java.sql.timestamp
without timezone (i´m getting 2007-09-23T10:10:10Z
and I pretend 2007-09-23T10:10:10
).
我试试:
Timestamp timestamp = Timestamp.valueOf("2007-09-23 10:10:10");
但在调试中我看到 cdate 是 2007-09-23T10:10:10.000+0100
而不是 2007-09-23T10:10:10
p>
but in debug i saw that the cdate is 2007-09-23T10:10:10.000+0100
instead of 2007-09-23T10:10:10
推荐答案
时间戳没有时区.当您将时间戳显示为字符串时,它会显示时间并提及时区,因为否则您无法知道它代表什么时间.它选择使用默认时区(您的),因为那是您最熟悉的.
A Timestamp doesn't have a timezone. When you display the timestamp as a String, it displays a time and mentions the timezone, because else you couldn't know what time it represents. And it chooses to use the default timezone (yours), because that's the one you're the most familiar with.
说,现在是 12:00:00 没有任何意义.说你的时区是 12:00:00 意味着什么.但是时间戳只包含一个瞬间.您可以使用 DateFormat 在您想要的任何时区显示这一瞬间.
Saying, it's 12:00:00 doesn't mean anything. Saying it's 12:00:00 in your timezone means something. But the timestamp only contains an instant in time. You may display this instant in time in any time zone you want using a DateFormat.
注意:Timestamp.valueOf("2010-10-23 12:05:16");
的意思是在默认时区中创建具有给定时间的时间戳".
Note: Timestamp.valueOf("2010-10-23 12:05:16");
means "create a timestamp with the given time in the default timezone".
这篇关于创建没有 timeZone 的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建没有 timeZone 的时间戳


基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01