San*_*jay 6 javascript momentjs
我正在使用MomentJS时区.但是,当我这样做时moment.tz.guess()
,它会返回错误拼写的时区.
const timezone = moment.tz.guess();
console.log(timezone); //returns Asia/Katmandu instead of Asia/Kathmandu
Run Code Online (Sandbox Code Playgroud)
是的,我可以编辑js文件并更正拼写,但我担心其他国家也是如此.由于我不知道它,这可能会降低用户体验!
是预期这种行为还是有任何方法可以修复它?
请参阅这篇文章为什么结果不同。如果您得到的结果Asia/Katmandu
返回值为Asia/Kathmandu
.
//for kathmandu, it returns Asia/Katmandu(chrome)
//returns Asia/Kathmandu (firfox);
var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
if(timeZone === 'Asia/Katmandu'){
timeZone = 'Asia/Kathmandu';
}
console.log(timeZone);
Run Code Online (Sandbox Code Playgroud)
MomentJs 演示
var timeZone = moment.tz.guess();
if(timeZone === 'Asia/Katmandu'){
timeZone = 'Asia/Kathmandu';
}
console.log(timeZone);
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone-with-data.js"></script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
387 次 |
最近记录: |