3

I am passing YYYY-MM-DD-hrs-min-sec as arguments in my node js application and getting wrong output,

Here is what I am passing in my nodeJs:

console.log("arrivaldateN", new Date("2019-11-25T15:48:43.14"))
//Op => 2019-11-25T10:18:43.140Z
console.log("arrivaldateN", new Date(2019, 10, 25, 15, 48,43))
// op => 2019-11-25T10:18:43.140Z

My expected output is like this 2019-11-25T15:48:43.140Z here I got wrong hrs and mins in node js Date object.

while doing the same thing in chrome console and it will give me correct output

> new Date(2019, 10, 25, 15, 48,43)
> Mon Nov 25 2019 15:48:43 GMT+0530 (India Standard Time)

is there anything wrong in the provided code?

Harsh Patel
  • 6,334
  • 10
  • 40
  • 73

1 Answers1

1

You can use toISOString() function.

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix "Z".

let arrivaldateN=new Date(2019, 10, 25, 10, 48,43);

console.log(arrivaldateN.toISOString());
Prabhjot Singh Kainth
  • 1,831
  • 2
  • 18
  • 26