mounish mounish - 27 days ago 18
jQuery Question

timezone convertion issue when system preferences and user preferences are different in javascript

date is not coming properly when my system preference Asia/Kolkata,user preferences input date is America/Los_Angeles both are different

date is coming properly when my system preference & user preferences same

jsfiddle example : http://jsfiddle.net/uq99udc9/728/

//system preference Asia/Kolkata
// input date America/Los_Angeles --- 2016-11-09 02:00:00
var date = new Date("2016-11-09 02:00:00");
var gmtdate = date.toGMTString(); -- converting into GMT
$("#divThai").text(moment.tz(gmtdate,'Asia/Kolkata'));
$("#divUsa").text(moment.tz(gmtdate,'America/Los_Angeles'));


any one help me out from this issue.

Thanks in Advance,

Answer

Try this:

// Parse the date in Los Angeles timezone.
const date = moment.tz('2016-11-09 02:00:00', 'America/Los_Angeles');
// Output the date.
console.log(date.toString());
// Output the date in Asia/Kolkata timezone.
console.log(date.tz('Asia/Kolkata').toString());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.9/moment-timezone-with-data.min.js"></script>