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:10p>
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 的时间戳
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
