extjs 计算日期之和_js日期与extjs日期不一致

2ff34e647e2e3cdfd8dca593e17d9b0a.png

在javascript中使用new Date()获取当前时间,也可以直接将时间格式的字符串转换为时间对象,如:new Date(‘2011-11-11’);

在firebug中输出日期为:

Date {Fri Nov 11 2011 08:00:00 GMT+0800}

既然已经指定了时区为GMT+0800,时间就不应该是08:00:00,就是这个原因带来了很多麻烦。

在extjs中,通过日期组件获取到的时间对象与js的时间有些区别,如果选择2011年11月11日,则可以看到得到的日期为:

Date {Fri Nov 11 2011 00:00:00 GMT+0800}

而此时如果需要使用到日期比较时,就会出现问题,因此需要将日期统一为一种形式。

extjs提供了这样的方法Ext.Date.clearTime():clearTime( Date date, Boolean clone ) : Date Attempts to clear all time information from this Date by setting the time to midnight of the same day, automatically adjusting for Daylight Saving Time (DST) where applicable. (note: DST timezone information for the browser’s host operating system is assumed to be up-to-date)

Parameters date : Date The date clone : Boolean true to create a clone of this date, clear the time and return it (defaults to false). Returns Date this or the clone.

可以在firebug中通过下面的代码查看区别:var a=new Date(); console.log(a); var b=Ext.Date.format(a,’Y-m-d’); var c=new Date(b); console.log(c); var d=Ext.Date.clearTime(c); console.log(d);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值