A 3rd API(mediamath,FYI) is requiring the following date format to set the date to 21 march EST
:
2019-03-21T00:00:00+America/New_York
How can I generate this string directly using the javascript date object?
Thank you.
A 3rd API(mediamath,FYI) is requiring the following date format to set the date to 21 march EST
:
2019-03-21T00:00:00+America/New_York
How can I generate this string directly using the javascript date object?
Thank you.
You can calculate moment
's
moment().format(moment.HTML5_FMT.DATETIME_LOCAL) // 2019-03-14T22:43
and
moment.tz.guess() // Asia/Yerevan
If you can use the moment and moment-timezone libraries, here is some sample code that will take your input and calculate the desired output.
let moment = require('moment-timezone');
let rawInput = "2019-03-21T00:00:00+America/New_York";
let separatorIndex = rawInput.indexOf("+");
let time = rawInput.substring(0, separatorIndex);
let zone = rawInput.substring(separatorIndex + 1);
let calculatedMoment = moment.tz(time, zone);
let yourOutput = calculatedMoment.format("DD MMM z");
//yourOutput now has "21 march EDT"
Reference: https://momentjs.com/timezone/docs/#/using-timezones