Parse JavaScript Date in local time zone
date, datetime, javascript, timezone
Solution
// dateString is the value from datetime-local
var dateInLocal = moment(dateString, "YYYY-MM-DDThh:mm");
Problem
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?