Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Timezone from Date object - Java [duplicate]

Can we get timezone details from java.util.Date object? I need to print the birthdate without affecting the timezone. Suppose someone has a birthdate on "12-15-1998 11:45:50 AM" with timezone America/Los_Angeles. Suppose I want to print birthdate in India. Then I don't want time zone in India change the birthdate to "12-16-1998 12:15:50 PM"? At the end, I just want to print "12-15-1998". thanks in advance.

like image 811
M_Gandhi Avatar asked Jun 10 '26 11:06

M_Gandhi


1 Answers

A java.util.Date does not have a time zone associated with it. Its toString() method may make it appear to have a time zone, but it doesn't. The time zone provided by toString() is the system default time zone.

A Calendar does have a time zone associated with it. And that appears to be what you are trying to do.

like image 195
thangdc94 Avatar answered Jun 13 '26 01:06

thangdc94