jquery - JavaScript test if date (in string format) is more than 30 days ago - Stack Overflow

i have the date in a string format like so '1122009' (mdyyyy)I need to test if that is gr

i have the date in a string format like so '11/2/2009' (m/d/yyyy)

I need to test if that is greater than 30 days ago.

Whats the easiest and least error-prone way to do this.

i have the date in a string format like so '11/2/2009' (m/d/yyyy)

I need to test if that is greater than 30 days ago.

Whats the easiest and least error-prone way to do this.

Share Improve this question asked Nov 2, 2009 at 22:00 Jon EricksonJon Erickson 115k45 gold badges139 silver badges178 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Something like this perhaps:

var then = new Date("11/2/2009").getTime(),
    now  = new Date().getTime(),
    thirtyDaysInMilliseconds = 2592000000;
if (now - then > thirtyDaysInMilliseconds) { doSomething(); }

You'll have to be sure your date meets the format (MM-DD-YYYY), but this should work:

var olddate = "11/02/2009"
var dt = Date.parse( olddate );
return ( ( Date.getTime() - dt.getTime() ) < 2592000000 );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744957531a4603285.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信