I want to write a function that can convert the given timestamp as per given timezone codes. For Example:
getTimeStampforZone(new Date(), 'PST') //gives timestamp in pacific
getTimeStampforZone(new Date(), 'EST') //gives timestamp in eastern
getTimeStampforZone(new Date(), 'CT') //gives timestamp in China time zone
I am able to do it for few time zones but looks lke there is no support in Safari for "All" timezones.
I don't want to use any library.
Here is my code:
function getZoneTime(date, timeZone) {
var options = {
timeZone: timeZone,
hour12: false,
hour: '2-digit',
minute: '2-digit'
};
var date = new Date(date);
var localizedDate = new Date(date.toLocaleDateString('en-US', options));
var localizedTime = date.toLocaleTimeString('en-US', options);
return localizedDate.toString('yyyy-MM-dd') +' '+ localizedTime;
}