Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date to LocalDateTime to DateTime using jodatime but how to add timezone

Tags:

jodatime

I dont' care if it is MST or MDT, but I have a LocalDateTime object with the time(ie. no timezone). I want to add MST or MDT and create a DateTime object such that I can get milliseconds since the epoch for storage and milliseconds from the epoch is in UTC of course just like System.currentTimeMillis is in UTC.

So is there a way to say MountainTime independent of savings or daylight time as it should know that from the date it has itself, correct? How to do that?

thanks, Dean

like image 382
Dean Hiller Avatar asked Dec 16 '22 16:12

Dean Hiller


1 Answers

A LocalDateTime is just a bunch of numbers (day, month, year, hour, minute...) that represent a civil (not a physic) concept. A Datetime is instead a physical concept (an instant of time), which in addition has a Timezone, and hence, it can be expressed in day/month/year.

To convert from a LocalDateTime to a Datetime, you need to specify a Timezone. This conversion is not totally well defined, though; because at DST transitions two different DateTimes can correspond to a same LocalDateTime.

like image 135
leonbloy Avatar answered Mar 01 '23 23:03

leonbloy