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 的时间戳


- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01