Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: Comparing dates in different timezones

My requirement is to do client side validation against a Date. The date will turn off functionality and will use an Eastern Timezone value. Daylight savings is not an issue here.

I have been attempting to use a Javascript Date as a constant and I've just discovered that the millisecond value of a Date will be different in different timezones.

new Date(2015, 2, 1, 4 , 59, 59).getTime()
1425207599000 --> result in Central
1425203999000 --> result in Eastern

Date has no setTimezoneOffset and seems like overriding getTimezoneOffset() isn't helpful either.

My approach is to use the long value of the date in EST timezone (1425203999000 ) as a constant and do a date1.getTime() > 1425203999000

Does this sound reasonable? Any considerations I've missed?

like image 622
Gervase Avatar asked Nov 19 '25 13:11

Gervase


1 Answers

This sounds completely reasonable, and it's how I roll. The long value of the date is not dependent on timezone. It measures milliseconds since some standard time in the 70's.

like image 141
Goodword Avatar answered Nov 22 '25 04:11

Goodword