-1

I use Dayjs library for date parsing/manipulation in nodejs. Consider a date = "2023-07-21T12:00:00+05:00". When I try to get utcOffset by using dayjs(date).utcOffset() it returns "60" in minutes, although offset in minutes of given date is "300".

I think it coverts the date into local-timezone where server is hosted and returns that utcOffset. But I want to extract offset from the given date like in this case "+05:00" or "300" in minutes. I tried string split method but that is not good as date format may change. Thanks in advance.

1 Answers1

0

While the timezone offset in your string is taken into account when parsing the string

JS dates don't contain a timezone.

The timezone is global for all dates and it's of the current environment.

date.getTimezoneOffset() returns the difference, in minutes, between date as evaluated in the UTC time zone and as evaluated in the local time zone — that is, the time zone of the host system in which the browser is being used (if the code is run from the Web in a browser), or otherwise the host system of whatever JavaScript runtime (for example, a Node.js environment) the code is executed in.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

Alexander Nenashev
  • 8,775
  • 2
  • 6
  • 17