我在jsfiddle http://jsfiddle.net/93pEd/174/上看到了这段代码。我决定修改我的代码 项目,因为它有点类似。 我在原点(左)转换为(右)
时添加了另一个下拉列表
请大家帮忙解释如何转换时间并将其放在输入文本字段中 这是我添加/编辑的代码 附:我没有改变javascript代码。
$(function(){
$('.location').each(function() {
var timeZone = $(this).data('tz');
var now = moment().tz(timeZone).format('HH:mm');
$(this).append( now );
});
});

<select>
<option><span class="location" data-tz="Africa/Tripoli">Tripoli: </span></span><br /><option>
<option><span class="location" data-tz="Europe/London">London: </span><option>
<option><span class="location" data-tz="Europe/London">London: </span><option>
<option><span class="location" data-tz="Asia/Tokyo">Tokyo </span><option>
</select>
<p>CONVERT TO</p>
<select>
<option><span class="location" data-tz="Africa/Tripoli">Tripoli: </span></span><br /><option>
<option><span class="location" data-tz="Europe/London">London: </span><option>
<option><span class="location" data-tz="Europe/London">London: </span><option>
<option><span class="location" data-tz="Asia/Tokyo">Tokyo </span><option>
</select>
<input type="text" id="gettime" value="">
&#13;
答案 0 :(得分:0)
$(document).ready(function(){
// get Bombay time
alert(calcTime('Bombay', '+5.5'));
// get Singapore time
alert(calcTime('Singapore', '+8'));
// get London time
alert(calcTime('London', '+1'));
});
function calcTime(city, offset) {
// create Date object for current location
d = new Date();
// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));
// return time as a string
return "The local time in " + city + " is " + nd.toLocaleString();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>