Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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).

I try:

Timestamp timestamp = Timestamp.valueOf("2007-09-23 10:10:10");

but in debug i saw that the cdate is 2007-09-23T10:10:10.000+0100 instead of 2007-09-23T10:10:10

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
361 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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.

Note: Timestamp.valueOf("2010-10-23 12:05:16"); means "create a timestamp with the given time in the default timezone".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...