Example: Y.Date.parse()

The Date module of the DataType Utility allows you to take a String or a Number (in milliseconds) value and convert it to Date. If no format is provided, the parse() method will accept any String or Number value supported by JavaScript's Date() constructor.

 

To convert a data value to a date, simply call the parse() function of the Y.Date class:

YUI().use("datatype-date", function(Y) {
    var date = Y.Date.parse("Jan 7, 2003", format);
    // date is a JavaScript Date object
});

A choice of a few format specifications has been provided in the dropdown box. The date in the example above requires no format since it is natively understood by the Date() constructor. Alternatively, format could have been given as "%b %D, %Y"