1

I have some date and times. The dates and times are in GMT . I am currently using formatTime to print the times. However, the times are being reset by formatTime to account for the different timezone. What I am trying to achieve is, if the time was 08:AM in 000Z, then it shall print 08:AM no matter where the app is being used, no matter the current timezone

For example, the full start and stop dates are shown below:

//start 
 '2017-12-12T08:00:00.000Z'

//stop
 '2017-12-31T09:00:00.000Z'

The start time and stop time are the time portions of start and stop

//start-time
  '0001-01-01T08:00:00.000+00:00'

//stop-time
  '0001-01-01T09:00:00.000+00:00'

I am currently trying to get the startTime and stopTime using

 const startTime = formatTime('0001-01-01T08:00:00.000+00:00'); 
 // {startTime} prints 3:00 AM instead of 8:00 AM 

 const stopTime = formatTime('0001-01-01T09:00:00.000+00:00');
 // {stopTime} prints 4:00 AM instead of 9:00 AM 

How do I make sure that start-time, and stop-time are displayed as 08:00 AM and 09:AM regardless of the current-time zone and the time-zone they were created in using formatTime ? Currently, displaying start time and stop time is resetting the time in regards to the current time zone. For example, 08:00 AM is being displayed as 3:00 AM as my current timezone is GMT-5. Thanks in advance !!

jungleMan
  • 838
  • 1
  • 8
  • 26
  • Possible duplicate of [How do you convert a JavaScript date to UTC?](https://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc) – Kraylog Dec 12 '17 at 10:29
  • Please read carefully the question. I have updated it. I am trying to format only the time to display exactly as in the way it was create, not the full dateTime . – jungleMan Dec 12 '17 at 10:52
  • The question I referenced deals with the exact same problem - how to ignore the timezone and display the date object in UTC (same as GMT in your case). – Kraylog Dec 12 '17 at 10:57
  • applying toISOString() to startTime and stopTime gives errors undefined is not an object. – jungleMan Dec 12 '17 at 11:03
  • startTime and stopTime are strings I am getting from an API. – jungleMan Dec 12 '17 at 11:03
  • Where does the `formatTime` function come from? – Kraylog Dec 12 '17 at 11:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161012/discussion-between-nimrod-argov-and-jungleman). – Kraylog Dec 12 '17 at 11:06

0 Answers0