Reputation: 97
I'm trying to use moment.js and moment-timezone.js to make the users able to change into their local timezone. But I'm having some difficulties while using moment-timezone.js . I followed their example, but it doesn't matter which timezone I select it always gives me my local time. Here is my code:
<html>
<head>
<title>Test</title>
<script src='scripts/jquery.min.js'></script>
<script src="scripts/moment.js"></script>
<script src="scripts/moment-timezone.js"></script>
<script src="scripts/moment-timezone-with-data.js"></script>
</head>
<body>
<span id="time">
</span>
<script>
$(document).ready(function(){
var dhaka = moment.tz("2015-09-01 12:00", "Asia/Dhaka");
var newYork = dhaka.clone().tz("America/New_York");
var losAngeles = dhaka.clone().tz("America/Los_Angeles");
var london = dhaka.clone().tz("America/Los_Angeles");
$('#time').html('Dhaka: ' + dhaka.format() + "<BR>New York: " + newYork.format() + "<br>Los Angeles: " + losAngeles.format() + "<br>London: " + london.format());
})
</script>
</body>
And my output is:
Dhaka: 2015-09-01T12:00:00+00:00
New York: 2015-09-01T12:00:00+00:00
Los Angeles: 2015-09-01T12:00:00+00:00
London: 2015-09-01T12:00:00+00:00
Am I doing something wrong? Why it's not working?
Upvotes: 1
Views: 485
Reputation: 630
<html>
<head>
<title>Test</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.0/moment-timezone-with-data.min.js"></script>
</head>
<body>
<span id="time">
</span>
<script>
$(document).ready(function(){
var dhaka = moment.tz("2015-09-01 12:00", "Asia/Dhaka");
var newYork = dhaka.clone().tz("America/New_York");
var losAngeles = dhaka.clone().tz("America/Los_Angeles");
var london = dhaka.clone().tz("America/Los_Angeles");
$('#time').html('Dhaka: ' + dhaka.format() + "<BR>New York: " + newYork.format() + "<br>Los Angeles: " + losAngeles.format() + "<br>London: " + london.format());
})
</script>
</body>
</html>
And here is jsfiddle link - https://jsfiddle.net/fgvr1rgL/
Upvotes: 3