YUI 3.x Home -

YUI Library Examples: DataType Utility: DataType.Date.parse()

DataType Utility: DataType.Date.parse()

The Date module of the DataType Utility allows you to take a data value and convert it to a number. The parse() method will accept any value supported by JavaScript's Date() constructor.

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

  1. YUI().use("datatype-date", function(Y) {
  2. var date = Y.DataType.Date.parse("Jan 7, 2003");
  3. // date is a JavaScript Date object
  4. });
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:

  1. YUI().use("datatype-date", function(Y) {
  2. // These all return dates
  3. var date = Y.DataType.Date.parse("December 17, 1995 03:24:00");
  4.  
  5. date = Y.DataType.Date.parse(1995,11,17);
  6.  
  7. date = Y.DataType.Date.parse(1995,11,17,3,24,0);
  8.  
  9. date = Y.DataType.Date.parse(948548583);
  10. });
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);
});

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings