瞬间语言环境设置不正确 [英] moment locale not set correctly

查看:56
本文介绍了瞬间语言环境设置不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试查找使用moment.js的测试存在问题,并且在亚利桑那州的服务器上运行时失败,而在英国本地运行时成功.我们在创建片刻之前手动设置了语言环境,然后可以看到已安装了本地"en-gb".

We're trying to find a problem with tests that use moment.js and fail when run on a server in Arizona but succeed when run locally here in the UK. We manually set the locale before creating a moment and can see that the local 'en-gb' is installed.

此小提琴突出了我认为的问题(需要先将计算机设置为亚利桑那州时区!)

This fiddle highlights what I think the problem is (Need to set computer to Arizona Time zone first!) https://jsfiddle.net/2ve10ax4/

moment.locale('en-gb');
console.log(moment.locale());
// en-gb
console.log(moment('2016-05-01T00:00:00+00:00').format()); 
// 2016-04-30T17:00:00-07:00

我希望看到有关"en-gb"语言环境的日期格式,但它显示有关亚利桑那时间的日期.我想念什么吗?

I'm expecting to see the date formatted with respect to 'en-gb' locale but it shows it with respect to Arizona time. Am I missing something?

推荐答案

阅读更多内容后,我相信

After reading more I believe parseZone is the correct solution, given that I am already including Time Zone information in the date string.

console.log(moment.parseZone('2016-05-01T00:00:00+00:00').format());

这篇关于瞬间语言环境设置不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆