0

Want to remove TimeZone details from date+time.(EmberJS)

Input: "2019-03-11T09:00:00.000+09:00" (GMT+9) .

Like to convert in this format "2019-03-11T09:00:00.000+00:00" (GMT+0)

Usecase: API Returning : timestamp: "2019-03-11T09:00:00.000+09:00"

UI TimeZone is : UTC+9

Currently UI Display: 3/11/2019 18:00

UI should show 3/11/2019 9:00

Anand Somani
  • 801
  • 1
  • 6
  • 15
  • 1
    `new Date("2019-03-11T09:00:00.000+09:00")` will convert to your local time. from there you can convert this to UTC, but not any other time zones. well, actually, now you can in modern browsers, but this post explains all that: https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone/15171030#15171030 – Steven Stark Mar 11 '19 at 23:22
  • 1
    So you're saying you want to convert the timezone to UTC but keep the same time-of-day? – Phil Mar 11 '19 at 23:24
  • thanks Steven and Phil for quick looks at my question, I updated my query with usecase. Please help me. – Anand Somani Mar 11 '19 at 23:54
  • Is moment.js or another library an option or do you need your own pure JS solution? – Techdragon Mar 12 '19 at 01:28

2 Answers2

0

If you just want to drop timezone from date that you receive as a string, you just need to use regular expression to remove '+09:00' part:

new Date('2019-03-11T09:00:00.000+09:00'.replace(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})[+\-]\d{2}:\d{2}/, '$1'))

Or, to replace timezone with UTC:

new Date('2019-03-11T09:00:00.000+09:00'.replace(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})[+\-]\d{2}:\d{2}/, '$1+00:00'))

If you want to convert between timezones you can use moment-timezone or luxon

Gennady Dogaev
  • 5,902
  • 1
  • 15
  • 23
0

Try using ember-moment addon

{{moment-format '12-1995-25' 'MM/DD/YYYY' 'MM-YYYY-DD'}}

Replace 12-1995-25 with your API returning date

Community
  • 1
  • 1
rinold simon
  • 2,782
  • 4
  • 20
  • 39