0

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
Neo
  • 4,550
  • 6
  • 34
  • 51

1 Answers1

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