0

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.

Community
  • 1
  • 1
zacurry
  • 716
  • 3
  • 8
  • 22
  • 1
    Are you trying to generate that date string based on the current local time and time zone? Or is it based on some other input? – benvc Mar 14 '19 at 20:45
  • Current local time and time zone . I want to set the end_date to month end 11.59pm EST and start date to current time and date EST. – zacurry Mar 15 '19 at 08:10

2 Answers2

0

You can calculate moment's

moment().format(moment.HTML5_FMT.DATETIME_LOCAL) // 2019-03-14T22:43

and

moment.tz.guess() // Asia/Yerevan
mix
  • 143
  • 6
0

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