I have used a Javascript function for converting date to UTC date as follows:
Date.prototype.convertToUTC = function () {
var month = this.getMonth();
var day = this.getDate();
var year = this.getFullYear();
return new Date(Date.UTC(year, month, day));
}
Now the problem arises when the date on which this function is applied is already in UTC. Since I don't know whether user will call this method on UTC/Local date, I want to ensure conversion happens only if it is not in UTC. Please help.
JavaScript Date object has the method getTimezoneOffset(). You could use that. Or use the getUTC* methods:
var d = new Date();
var utcyear = d.getUTCFullYear();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With