Gervase
Gervase

Reputation: 1030

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?

Upvotes: 3

Views: 2765

Answers (1)

Goodword
Goodword

Reputation: 1645

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.

Upvotes: 2

Related Questions