I have a date format is GMT or UTC.
var mydate = '2020-01-14T17:43:37.000Z'
I want to convert this date in IST format so according to this date the output I need in this format.
var date = '2020-Jan-15 12:45'
datejavascriptpsttimezoneutc
I have a date format is GMT or UTC.
var mydate = '2020-01-14T17:43:37.000Z'
I want to convert this date in IST format so according to this date the output I need in this format.
var date = '2020-Jan-15 12:45'
Best Solution
You can specify an IANA time zone identifier in the options passed to
toLocaleString. The identifier for India isAsia/Kolkata.This will do the correct time zone conversion, as the input is in UTC (as specified by the
Zat the end).undefinedmeans to use the user's locale for the formatting of the date and time. This is usually what you want. If you want a more particular format (like what you specified in your question), you can provide a specific locale string and/or adjust the other options fortoLocaleString, as given in the docs.Also, note that the conversion in your question is incorrect. India is 5 hours an 30 minutes offset from UTC. Thus the correct output is
2020-01-14 23:13:37(in whatever format you like)