I am asking the user to input a date and time into my application. The user will input a time based on the timezone they are in. When I save this date and time to my database I want to convert the time to UTC so that when I query by time (which is done in UTC) I can find the entries.
This is what I've currently done :
var date = new Date();
var dateString = "0" + (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear() + " " + time;
//format date
date = moment(dateString, "MM/DD/YYYY HH:mm a");
date = new Date(date).toISOString();
Where time is the time the user enters (ex if I want to schedule something for 11:00am, time = 11:00am)
When this is saved to the database, it looks like :
ISODate("2016-05-09T11:00:00Z")
which is not correct since that is a EST saved as Zulu time.
How can I convert the time (I am using moment) to be saved as the correct Zulu time?