0

I had problem with UTC time . I have a date

Thu Nov 23 2017 00:00:00 GMT+0700 (ICT)

And now want to convert to

23 Nov 2017 17:00:00 GMT

But result is after convert is

22 Nov 2017 17:00:00 GMT

This is my code:

 let myDate = new Date(v.date);
 /// myDate = **Thu Nov 23 2017 00:00:00 GMT+0700 (ICT)**;
 let myDateConvert = myDate.toUTCString();
 /// myDateConvert = **22 Nov 2017 17:00:00 GMT**;

I use react-datepicker and momentjs

enter image description here

Thanks all with any helping

Thuc Hồ
  • 75
  • 3
  • 12
  • 2
    `2017-11-23 00:00:00 +07:00` is `2017-11-22 17:00:00 +00:00`, why you are expecting `Nov 23`? – VincenzoC Nov 22 '17 at 10:57
  • I'm using momentjs and i need to get correct date is 2017-11-23 to push to server API. If i dont convert date to UTC , my server would lost a day . – Thuc Hồ Nov 22 '17 at 11:03
  • 1
    There is no momentjs in your code sample, anyway even if you use momentjs `2017-11-23 00:00:00 +07:00` will always be converted into `2017-11-22 17:00:00 +00:00`, see [here](https://www.timeanddate.com/worldclock/converter.html?iso=20171122T170000&p1=tz_ict&p2=1440). – VincenzoC Nov 22 '17 at 11:10
  • @VincenzoC , i added more image when i selected a day in react-datepicker. I only convert from ITC to UTC, my location in Viet Nam – Thuc Hồ Nov 22 '17 at 11:24
  • 1
    @ThucHồ Both are same , store the date in utc format, while retrieving from server convert to local time again. – Durga Nov 22 '17 at 12:32
  • Thanks @Durga, I'll try – Thuc Hồ Nov 23 '17 at 02:56
  • I saw and resolved problem. I just need to add more my country hour UTC (+7) before send to server . Thank @VincenzoC and Durga once again `let offset = moment().utcOffset() / 60; let myStringDate = date.toISOString(); return moment(new Date(new Date(myStringDate).getTime() + 60 * 60 * offset * 1000)).utc();` – Thuc Hồ Nov 23 '17 at 04:15

0 Answers0