javascript:新的日期,如何设置默认年份? [英] javascript: new date, how to set default year?

查看:121
本文介绍了javascript:新的日期,如何设置默认年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组日期w /或wo /年,如下所示:

I have a set of dates w/ or wo/ year, like the following:

10/1/2010
10/1
1-Oct
1-Oct 2006
Jan 4
Jan 4, 2008

当我尝试使用新的Date()解析它们时,
对于那些没有年份的日期,我的年份为2001
eg

When I tried to parse them using new Date(), for those date that don't have year, I got year as 2001 e.g.

a=new Date("Jan 4")
Thu Jan 04 2001 00:00:00 GMT-0500 (EST)

我想解析所有的日期。如果他们有年,使用那一年(2010年,2006年,2008年在上述日期)。否则,使用2011

I want to parse all the dates. If they have year, use that year(2010, 2006, 2008 in the above dates). otherwise, use 2011

任何人都可以帮助?

谢谢,

Cheng

推荐答案

使用 DateJS 用于解析日期。 Date 构造函数的解析器非常有限。

Use DateJS for parsing dates. The Date constructor's parser is very limited.

这篇关于javascript:新的日期,如何设置默认年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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