0

I have a weird issue, I'm sending new Date() to API in NextJS. When I check the new Date() in React side, it shows the current local time.

But when I console.log() the request in API side, it doesn't show the local date I'm sending, instead it shows minus 3 by hours. For example, below code

// Sending from React via POST
send({currentTime: new Date()}) // console logs 23:30:30

//API console log
console.log(req.body.currentTime) // console logs 20:30:30

My timezone is UTC+3, so API side doesn't take the time I'm sending and seems like somehow it changes it to the UTC-0 time zone.

Why it doesn't get the local time I'm sending?

GLHF
  • 3,835
  • 10
  • 38
  • 83
  • So `console.log(new Date(req.body.currentTime))` and you will get the date you want. – Mohamed Karkotly Jul 03 '22 at 21:01
  • @Mohamed.Karkotly Nope, it still prints minus 3 hours. – GLHF Jul 03 '22 at 21:06
  • API uses Node.js time zone, and the client uses your local time zone. You can set the time with [date](https://stackoverflow.com/a/48206857/15304814) or with [Intl date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options) – Sean W Jul 03 '22 at 22:07

0 Answers0