翻閱古今
2019-04-18 14:15:29
我想用時(shí)區(qū)而不是GMT創(chuàng)建javascript時(shí)間所以GMT悉尼時(shí)間var date = new Date('2019-05-17' + ' ' + '01:00' + ' GMT+10:00');哪個(gè)有效,但在夏令時(shí)期間它改為GMT + 11:00,所以我嘗試了這個(gè)不起作用var date = new Date('2019-05-17' + ' ' + '01:00').toLocaleString("en-US", {timeZone: "Australia/Sydney"})請告訴我如何正確地做到這一點(diǎn),而無需增加/刪除夏令時(shí)
2 回答

慕桂英3389331
TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以將Intl.DateTimeFormat與自定義選項(xiàng)一起使用。
// Set a date
const date = new Date();
// Set the datetime options
const opts = {
year: 'numeric', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
timeZone: 'Australia/Sydney', timeZoneName: 'short'
};
// Set the formatted date
const audate = new Intl.DateTimeFormat('en-AU', opts).format(date);
document.write('Sidney, AU datetime is: ' + audate);
添加回答
舉報(bào)
0/150
提交
取消