javascriptjavatypescriptdatetimeoffsetoffsetdatetime

JavaScript/TypeScript how to build OffsetDateTime like in Java?


I am very new to java script, how to build offset date time in javascript, which I use to use to call and API which gets date time in string.

2020-08-27T22:54:36.922Z -> Like this in JavaScript/TypeScript

The samething in Java i will do something like this.

OffsetDateTime.now().toString()

Please let me know. The frontend is Javascript and I am planning to get offset date as string in the API and process that in the Java Handler in the backend.


Solution

  • It sounds like you want the toISOString() method on Date. You would call that on a freshly created new Date() instance that initializes to the current time.

    console.log(new Date().toISOString())

    Documentation here