0
import DateTimePicker from 'react-widgets'
import Moment from 'moment'
import momentLocalizer from 'react-widgets-moment';

DateTimePicker field contains "Wed Jan 16 2018 23:53:32". (My timezone GMT+02)

But when I send request : date = 2018-01-16T21:53:32.919Z

befev
  • 71
  • 7
  • 3
    A `Date` object doesn't have a time zone - its simple string representation uses the local time zone, but it just represents an instant in time. 2018-01-16T21:53:32.919Z and Wed Jan 16 2018 23:53:32 GMT+0200 are the same instant in time, so it's unclear what you're asking... – Jon Skeet Jan 16 '18 at 22:17
  • (And note that GMT+0200 and GMT+00 are different...) – Jon Skeet Jan 16 '18 at 22:17
  • I mean I send 23:53. But receive 21:53 – befev Jan 16 '18 at 22:19
  • 1
    23:53 at an offset of UTC+2 is the same as 21:53 UTC. They're the same instant in time. – Jon Skeet Jan 16 '18 at 22:19
  • Yes, because the two timestamps use different time zones, but they represent the same moment in time. – RobG Jan 16 '18 at 22:20
  • @befev—how to fix what? Perhaps see [*new Date() converts timezone*](https://stackoverflow.com/questions/29577879/new-date-converts-timezone). Note that what the console prints and what *Date.prototype.toString* return may be different (consoles aren't standardised), and the value of [*Date.prototype.toString*](http://www.ecma-international.org/ecma-262/8.0/index.html#sec-date.prototype.tostring) is entirely implementation dependent. – RobG Jan 16 '18 at 22:26
  • If you want the Date in a specific format, see [*Where can I find documentation on formatting a date in JavaScript?*](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) It is common to exchange time stamps as ISO 8601 UTC as a *de facto* standard. – RobG Jan 16 '18 at 22:28

1 Answers1

0

DateTimePicker is not converting timezone at all. It saves values as a Data Object.

The reason was in the Axios library, which does JSON.stringify() for the data object.

JSON.stringify() tries to call toJSON() method, so as the result Date is converted to string with ISO-8601 standard.

On the other hand, if try to display Date Object as a string (e.g. console.log()), method toString() will be automatically called, what represents the value in local timezone.

befev
  • 71
  • 7