0
如何在UTC中重新設置時間標記和相同類中的ISO 8601時間戳,並通過JavaScript調整到用戶區域設置和時區?如何在UTC中重新設置時間標記和相同類中的ISO 8601時間戳,並通過JavaScript調整到用戶區域設置和時區?
我確實有一個html頁面,其中包含一個帶有多個時間戳的HTML頁面,採用ISO 8601格式,採用UTC時間標籤封裝在同一個類中。
我想將它們重新格式化爲用戶區域設置格式和時區更正。
我想出了下面的代碼。在提到的評論中,我需要在TODO中添加哪些內容?
<!--- table with timestamps in ISO 8601 format and UTC --->
<table>
<tr><td>1: </td><td><time class="UTC_ISO_Date">2013-02-07T23:00:00.000Z</time></td></tr>
<tr><td>2: </td><td><time class="UTC_ISO_Date">2015-06-09T21:30:00.000Z</time></td></tr>
<tr><td>3: </td><td><time class="UTC_ISO_Date">2016-03-022T09:00:00.000Z</time></td></tr>
</table>
// get the timezone of the user out of the browser
var timezone = jstz.determine();
var usertz = timezone.name();
// TODO: get the locale of the user out of the browser
// iterate over classes="UTC_ISO_Date" with each()
$('.UTC_ISO_Date').each(function(i, obj) {
// format the timestamps into the correspondent format of the user locale and adjust to the users timezone
var formattedTimestamp = moment(i);
// TODO: update the value in the current class
});
請添加一個示例,您想實現什麼。 –
使用[moment.js](http://momentjs.com/)進行時間和日期操作。 –
<腳本src =「https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.3/moment-timezone.js」> 我已包含Moment.js,但未顯示。< – Thorsten