我尝试使用moment.js和moment-timezone.js让用户能够更改为他们的本地时区。但是我在使用moment-timezone.js时遇到了一些困难。我按照他们的例子,但我选择的时区并不重要,它总是给我当地时间。这是我的代码:
<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>
我的输出是:
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
我做错了吗?为什么它不起作用?