Q:

Convert a date to UTC based on timezones

I want to convert datetimes with different timezones to UTC format so I can further manipulate them. The dates are retrieved from a backend, but for ease I am giving just some examples:
var k = "2017-11-20 03:35 PM";
var timeZone = "Asia/Karachi";
// Offset UTC +5:00 hours, so should be 10:35 AM

var p = "2017-11-20 11:50 AM";
var timeZone = "US/Eastern";
// Offset UTC -5:00 hours, so should be 16:50 PM

I just want to convert the date variable to UTC so I get the actual time in UTC format. Note there can be multiple/different timezones, so it's just an example.

A:

I'd recommend using a library that deals with this type of thing exclusively. Moment.js is a very good one.
This video by Tom Scott beautifully explains the difficulty with dealing with time and date stuff yourself.
var myTime = moment.tz("2017-11-20 03:35 PM", "Asia/Karachi");
var myTimeUTC = myTime.clone().tz('UTC');

