I've been using toISOString
to serialize momentJS date before sending to the server via jQuery. It works fine for me except it converts date to UTC but I need to keep the local timezone. Does momentJS have a method for this?
var tz = moment. tz. guess(); It will return an IANA time zone identifier, such as America/Los_Angeles for the US Pacific time zone.
To change the default time zone, use moment. tz. setDefault with a valid time zone.
The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss. sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .
Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.
You can simply call .format()
without any parameters.
Added in 2.20.0:
moment().toISOString(true)
Output:
"2018-05-13T16:16:13.507+03:00"
Found answer here.
Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With