创建日期时,瞬间js默认时区不起作用(Moment js default timezone not working when creating date)
请参阅以下代码片段。
问题1:我正在为时刻js设置默认时区。 但是在设置之后,如果我从一刻开始检索时区,那就不是我刚设置的时区。
console.log("Currrent timezone: "); console.log(moment.tz()); console.log("Updating timezone: "); console.log("America/Lima"); moment.tz.setDefault("America/Lima"); console.log("Currrent timezone after updating: "); console.log(moment.tz());
以下日志被打印出来:
Currrent timezone: Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Nov 15 2017 13:39:45 GMT+0500 (Pakistan Standard Time), …} Updating timezone: America/Lima Currrent timezone after updating: Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Nov 15 2017 13:39:45 GMT+0500 (Pakistan Standard Time), …}
问题2:另一个问题是,我设置的默认时区应用于moment.format()函数,但从当前创建新的日期对象时不应用。
console.log(moment(new Date()).toDate()); // this uses user browser timezone // prints Wed Nov 15 2017 13:57:40 GMT+0500 (Pakistan Standard Time) // I want it to give the time in the timezone which i just set above console.log(moment(new Date()).local().toDate()); // prints Wed Nov 15 2017 13:57:40 GMT+0500 (Pakistan Standard Time) console.log(moment(new Date()).format()); // this uses the timezone which I set above in moment default timezone. This is correct intended behavior // prints: 2017-11-15T03:57:40-05:00
Please refer to the following code snippets.
Problem 1: I am setting default timezone for moment js. But right after setting it, If I retrieve the timezone from moment it is not what I just set.
console.log("Currrent timezone: "); console.log(moment.tz()); console.log("Updating timezone: "); console.log("America/Lima"); moment.tz.setDefault("America/Lima"); console.log("Currrent timezone after updating: "); console.log(moment.tz());
Following log is printed:
Currrent timezone: Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Nov 15 2017 13:39:45 GMT+0500 (Pakistan Standard Time), …} Updating timezone: America/Lima Currrent timezone after updating: Moment {_isAMomentObject: true, _isUTC: true, _pf: {…}, _locale: Locale, _d: Wed Nov 15 2017 13:39:45 GMT+0500 (Pakistan Standard Time), …}
Problem 2: Also another problem is that, the default timezone which I set is applied to moment.format() function but not applied when creating new date objects from moment.
console.log(moment(new Date()).toDate()); // this uses user browser timezone // prints Wed Nov 15 2017 13:57:40 GMT+0500 (Pakistan Standard Time) // I want it to give the time in the timezone which i just set above console.log(moment(new Date()).local().toDate()); // prints Wed Nov 15 2017 13:57:40 GMT+0500 (Pakistan Standard Time) console.log(moment(new Date()).format()); // this uses the timezone which I set above in moment default timezone. This is correct intended behavior // prints: 2017-11-15T03:57:40-05:00
原文:https://stackoverflow.com/questions/47303375
满意答案
{Binding Key}
是{Binding Path=Key}
简写。 这将返回当前DataContext
上Key
属性的值。
{Binding Key}
is shorthand for{Binding Path=Key}
. This will return the value of theKey
property on the currentDataContext
.
相关问答
更多silverlight在绑定中的表达(silverlight expression in binding)
Silverlight {Binding}不会访问类成员(Silverlight {Binding} won't access class members)
Keylight上的Silverlight双向数据绑定(Silverlight Two Way Data Binding on Key Up)
Silverlight 4中的WS绑定(WS Binding in Silverlight 4)
如何防止绑定刷新(How To Prevent Binding Refresh)
Silverlight {Binding Key} - 请刷新我的记忆?(Silverlight {Binding Key} - Please refresh my memory?)
SilverLight Datagrid刷新(SilverLight Datagrid refresh)
Silverlight内存泄漏(Silverlight Memory Leak)
Image Binding,Silverlight,C#,WP7(Image Binding, Silverlight, C#, WP7)
Silverlight ListboxItem可见性绑定(Silverlight ListboxItem Visibility binding)
相关文章
更多Working on Free Software
在java.util.Date中,如何比较两个Date的大小,精确到分
如何加载JS,JS应该放在什么位置?-高性能web开发
强力推荐几款JS插件,
两种js function 声明方式
jQuery表格插件jqGrid(jquery.jqGrid.js)
ant打包时自动压缩js和css
用SimpleDateFormat把字符串转换成Date的时候报NumberFormatException
Backbone.js的技巧和模式
js中2个等号与3个等号的区别
最新问答
更多python的访问器方法有哪些
使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
透明度错误IE11(Transparency bug IE11)
linux的基本操作命令。。。
响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements)
它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640
Copyright ©2023
peixunduo.com All
Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!