Ash Archin
Ash Archin

Reputation: 451

How can I convert this Local time to UTC

honestly I'm a liitle bit confused and don't know how to solve this issue so if the question is kind of silly I'm sorry :) so the situation is I have a time range that I get from server which is for reservation time range for a product consider this two:

"startWorkingHour": "0001-01-01T08:00:00",
"finishWorkingHour": "0001-01-01T17:00:00"

these time are UTC times. and the problem is I need to somehow convert user selected time which is local to UTC and that time must be in between of those two times. for example user selected 8:00 AM from time picker and format is like 2021-07-05T03:30:12.498Z and I don't want this I want this to be 2021-07-05T08:00:12.498Z so my server could accept it. how can I achieve that?

Upvotes: 0

Views: 69

Answers (1)

Joel Hager
Joel Hager

Reputation: 3440

You convert to UTC via toUTCString()

const dates = {
startWorkingHour: "0001-01-01T08:00:00",
finishWorkingHour: "0001-01-01T17:00:00"
}

const date = new Date()

console.log(date, date.toUTCString(), new Date(dates.startWorkingHour).toString())

Upvotes: 2

Related Questions