Date.prototype.format(mask)

Description:

Generate the date value string according the specified format

Parameters:

  • mask
    • Type: string

Returned Value:

  • Date value string generated.

Format Legends:

  • d: The day of the month, from 1 through 31.
  • dd: The day of the month, from 01 through 31.
  • ddd: The abbreviated name of the day of the week. Such as: 'Sun', 'Mon', 'Tue', 'Wed'...
  • dddd: The full name of the day of the week. Such as: 'Sunday', 'Monday', 'Tuesday'...
  • M: The month, from 1 through 12.
  • MM: The month, from 01 through 12.
  • MMM: The abbreviated name of the month. Such as: 'Jan', 'Feb', 'Mar'...
  • MMMM: The full name of the month. Such as: 'January', 'February', 'March'...
  • yy: The year, from 00 to 99. Such as: 98, 99, 00...
  • yyyy: The year as a four-digit number. Such as: 1998, 1999, 2000...
  • m: The minute, from 0 through 59.
  • mm: The minute, from 00 through 59.
  • s: The second, from 0 through 59.
  • ss: The second, from 00 through 59.
  • fff: The milliseconds in a date and time value.
  • ff: The hundredths of a second in a date and time value.
  • tt: The am/pm designator.
  • TT: The AM/PM designator.
  • Z: The quoted strings with the surrounding quotes removed

Sample

var testDate = new Date(2012, 4, 2, 18, 01, 03);
document.write(testDate.format("yyyy-MM-dd HH:mm:ss"));
//Result: "2012-05-02 18:01:03"

Last edited Aug 20, 2012 at 9:44 AM by rynnwang, version 1

Comments

No comments yet.