Rob Fletcher
Rob Fletcher

Reputation: 8627

Parse JavaScript Date in local time zone

I'm trying to parse the value of a datetime-local input so the format is 'yyyy-mm-ddTHH:mm'. I want the assumption to be that I'm parsing in the local time zone of the user, i.e. if they enter 09:00 they mean 9am in their time zone.

Also not just the current time offset, e.g. if the user enters a date in June then they mean daylight savings time regardless of the fact it's now November and DST has ended.

I've tried using regular Date objects and moment.js but the assumption is always that the time zone is UTC.

Is there a way to do this?

Upvotes: 9

Views: 2802

Answers (1)

Naresha
Naresha

Reputation: 199

// dateString is the value from datetime-local
var dateInLocal = moment(dateString, "YYYY-MM-DDThh:mm");

Upvotes: 2

Related Questions