The Date module of the DataType Utility allows you to format a JavaScript Date object into a string with strftime
syntax. This method allows you to specify any tokenized HTML value as the format. However, in this example the formatted output will be escaped for security.
NOTE: As of 3.1.0, the formatting patterns used by DateType.Date can be driven by external language resource bundles as described in the "Formatting Dates Using Language Resource Bundles" Example. This examples currently uses the 3.0.0 dateFormat
and locale
instance configuration support which have been deprecated.
To convert a data value to a date, simply call the parse()
function of the DataType.Date class:
YUI().use("datatype-date", function(Y) { var date = Y.DataType.Date.parse("Jan 7, 2003"); // date is a JavaScript Date object });
Under the hood, the data value is converted to a date via the Date()
constructor:
YUI().use("datatype-date", function(Y) { // These all return dates var date = Y.DataType.Date.parse("December 17, 1995 03:24:00"); date = Y.DataType.Date.parse(1995,11,17); date = Y.DataType.Date.parse(1995,11,17,3,24,0); date = Y.DataType.Date.parse(948548583); });