简体   繁体   中英

JavaScript Globalize: How to compare two dates?

I would like to compare two dates.

Problem : The date and time strings are formatted by Globalize . So, I'm not able to split the values the same way and have to differenciate everytime.

I would like to have a function like...

Globalize.getTimestamp("21.12.2012 19:41", "d t") // value, pattern

...but cannot find it.

That's the form:

<label>From</label>
<input type="text" name="start_date" value="21.12.2012" class="datepicker"/>
<input type="text" name="start_time" value="19:41" class="timepicker"/>

<label>To</label>
<input type="text" name="end_date" value="22.12.2012" class="datepicker"/>
<input type="text" name="end_time" value="19:41" class="timepicker"/>

Edit : That's how to parse the date:

Globalize.parseDate($("[name='start_date']").val()); // 21.12.2012

But parsing the date with time doesn't work:

Globalize.parseDate($("[name='start_date']").val() + " " + $("[name='start_time']").val()); // 21.12.2012 19:41

I'd like to avoid developing the Globalize.getTimestamp()-function. How would you solve this problem? Any ideas? Thanks!

If the strings have been written using Globalize, you should read them using Globalize, with the same locale (culture). After calling Globalize.parseDate(), you have Date objects that can easily be compared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM