0

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.

CoderTest
  • 35
  • 1
  • 6

2 Answers2

2

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

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
0

To get the offset in JavaScript:

var now = new Date(); var offset = now.getTimezoneOffset();

You can do math from there for your specific implementation (i.e./ 60).

Spencer Sullivan
  • 527
  • 6
  • 13