检查一个日期是否晚于第一个日期 [英] Check if one date is later then first date
问题描述
假设我有2个日期格式的b / m格式:
日期1和日期2
如何检查Date2是否晚于日期1?
Date1。 2006年11月21日09:00:00
Date2。 21-Nov-2006 10:00:00 PM
请指教。
谢谢。
Hi,
Let''s say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
Date1. 21-Nov-2006 09:00:00 PM
Date2. 21-Nov-2006 10:00:00 PM
Please advise.
Thanks.
推荐答案
用户在11/27/2006上午8:12发表以下内容:
user said the following on 11/27/2006 8:12 AM:
假设我有2个日期格式的b / m格式:
日期1和日期2
>
如何检查Date2是否晚于Date 1?
Hi,
Let''s say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
从它们创建日期对象并进行比较。
-
Randy
机会有利于准备好的思想
comp.lang.javascript常见问题 - http://jibbering.com/faq
Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb写道:
Randy Webb wrote:
用户在11/27/2006上午8:12发表以下内容:
user said the following on 11/27/2006 8:12 AM:
假设我有2个日期格式的b / m格式:
日期1和日期2
>
如何检查Date2是否晚于Date 1?
Hi,
Let''s say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
从它们创建日期对象并进行比较。
-
Randy
机会有利于准备好的思想
comp.lang.javascript常见问题 - http://jibbering.com/faq
Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/
是的。我曾尝试使用setfullyear()等等进行比较。但
问题是时间问题。有没有方法可以读取指定的日期格式
以上?
Yes. I have tried to use setfullyear() ,etc etc and do compare. But the
problem is time. Are there ways to read in the date format specified
above?
user写道:
user wrote:
假设我有2个日期的b / m格式:
日期1和日期2
如何检查Date2是否晚于日期1?
Date1。 2006年11月21日09:00:00
Date2。 21-Nov-2006 10:00:00 PM
请指教。
谢谢。
Hi,
Let''s say I have 2 dates in the b/m format:
Date 1 and date 2
How do I check whether Date2 is later than Date 1?
Date1. 21-Nov-2006 09:00:00 PM
Date2. 21-Nov-2006 10:00:00 PM
Please advise.
Thanks.
您需要将两个日期都放入日期对象中。 Date对象
实际上会解析这些,如果你删除日期中的短划线和
用空格替换它。假设你可以这样做......
var date1 = new Date(''2006年11月21日09:00:00 PM'');
var date2 = new Date(''2006年11月21日10:00:00 PM'');
date1和date2现在有一些总毫秒,因为有些任意
可以追溯到70年代。具体来说......
date1:1,164,164,400,000
date2:1,164,168,000,000
(你可以看到这个数字仅仅是做一个document.write(date1 * 1),
会强制它把它作为一个int。
一旦解析了你的日期,你就可以了简单地做if(date2 date1)。
如果你是一个小偏执狂,你可以通过if((date2 * 1)>
强制演员(date1 * 1)。
您还可以从date1中减去date2并获得确切的时间
毫秒,秒,分钟,小时,天,周,年两个
值之间。
希望有所帮助。
-
--- -------------------------------------------------- ----------------------
http://www.hunlock.com - 永久在建(并以此为荣!)
You''ll need to get both dates into the date object. The Date object
will actually will parse these if you remove the dashes in the date and
replace it with a space. Assuming you can do that...
var date1 = new Date(''21 Nov 2006 09:00:00 PM'');
var date2 = new Date(''21 Nov 2006 10:00:00 PM'');
date1 and date2 now have the total milliseconds since some arbitrary
date back in the 70s. Specifically...
date1: 1,164,164,400,000
date2: 1,164,168,000,000
(you can see this number just by doing a document.write(date1*1), which
will force it to cast it as an int.
Once you have your dates parsed you can simply do if (date2 date1).
If you''re a little paranoid you can force a cast by if ((date2*1) >
(date1*1)).
You can also subtract date2 from date1 and get the exact time in
milliseconds,seconds,minutes, hours, days, weeks, years between the two
values.
Hope that helps.
--
---------------------------------------------------------------------------
http://www.hunlock.com -- Permanently under construction (And proud of it!)
这篇关于检查一个日期是否晚于第一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!