0

So I have an issue for which I couldn't find a solution - I'm making a simple GET request, which returns a JSON with all kinds of data, including timestamps. The issue is, that, for example - my timestamps retrieved from the database are 12:00:00, but after GET they're changed to 09:00:00. Why is this, and how can this be fixed?

I'm using axios for my GET request, but that doesn't seem to matter, because when making the same GET request with Insomnia, I still get timestamps with changed hours (-3).

Eddie
  • 47
  • 7
  • the Date element in JavaScript has a long history of headaches, long story short, toJSON returns the date without timezone, Date on the other hand displays the date including the timezone change. Please check this link for more info: https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone – savageGoat May 15 '21 at 10:13

1 Answers1

0

js uses local machine's timezone by defualt, you need change the js timezone in client side, or you can change timezone in server and send formatted date time string through json.
Here's a good article if you want to change timezones in js.

Hirbod
  • 67
  • 11