I am creating a date in node js, my server is in IST, I want to determine if the date would come PDT or PST (i.e. If the Daylight saving is on or off). If my server was in PST/PDT time it would be automatically decide. Is there any way I can determine this?
Asked
Active
Viewed 2,939 times
0
-
1Not for future dates. The rules can change. – David Schwartz Jan 23 '14 at 12:44
-
how about past dates? when i create new Date("dateString") it's able to decide PST or PDT if my system time is in PT. I want to do the same from IST system time. – Neo Jan 23 '14 at 12:50
-
1The answer in the dup post is one way. Another would be using the `isDST` function from [moment.js](http://momentjs.com) – Matt Johnson-Pint Jan 26 '14 at 06:07
1 Answers
0
After creating the date with ...Date() you are able to retrieve the timezone offset of the client with ...getTimezoneOffset(). You can not tell whether the client is in DST or not, but you have the absolute amount to GMT/UTC. Or, you can further retrieve the time a UTC timestamp and convert that to whatever you want on the server.
Axel Amthor
- 10,980
- 1
- 25
- 44
-
I will get a date string "10/23/2014 00:00:00" that is from PT. I send to a client which may be in any time zone but i want to determine that day on PT was daylight saving on or not. – Neo Jan 23 '14 at 12:59
-
Convert to UTC timestamp in milliseconds, send that to the client and create the date from milliseconds instead of a formatted string. Whatever timezone with or w/o DST the client is in, the date will be proper, since it's set from UTC: `ndate = new Date(); ndate.setTime(UTCinMillisFromServer);` – Axel Amthor Jan 23 '14 at 13:05
-
What if the local machine is in a different timezone (not PST or PDT)? – Aniket Suryavanshi Oct 29 '18 at 07:12
-
Actually that doesn't matter at all: submit UTC and the client will transform in his TZ, regardless which one this is and whether it has or not DST etc. – Axel Amthor Oct 31 '18 at 11:05