Examples - Dates and Time

Date and time formatting and validation can be quite tedious to get right. Spiderscript's SS.datetime.js provides functions that help simplify the process.

These functions are used in the HTML form validation which can been seen in the validation example.

From Format To
1/2/2008 MMMM dd yyyy
12/04/2001 dddd dd MMMM yy
12/31/2005 dd.MM.yyyy
05/05/2003 12:47 dddd dd MMMM yyyy HH:mm:ss
07/08/2004 9:52pm HH:mm:ss
16/11/2008 13:52:54.591 dd-MM-yyyy HH.mm.ss.fff

In the example above, the input date is assumed to be in the format dd/MM/yyyy. This is because the default locale settings (SS.global.locale.dateformat = "MM/dd/yyyy";) have been overridden to match the settings used in Great Britain. e.g. SS.global.locale = new SS.locale("gb");. See SS.locale for more information on locale settings.
If the date is input in a different format e.g. MM/dd/yyyy and the value is not ambiguous e.g. 03/15/2008 then the date parse routine will be able to match this. For ambiguous matches, the default locale value or first match is used.