API Docs for:
Show:

Formatter.date Class

Defined in: ../lib/pat.js:1158
Module: pat

Functions ought to format date components.

Item Index

Methods

Methods

abbreviatedMonthName

(
  • date
  • culture
)
String static

Defined in ../lib/pat.js:1274

Returns the culture-specific abbreviated month name specfied by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • culture Object

    Culture information

Returns:

String:

abbreviatedTimezone

(
  • date
)
String static

Defined in ../lib/pat.js:1391

Returns a string representing the time zone abbreviation specified by the given date.

Parameters:

  • date Date

    Interpreted as a date with the same timezone as provided by the host OS.

Returns:

String:

abbreviatedWeekdayName

(
  • date
  • culture
)
String static

Defined in ../lib/pat.js:1297

Returns the culture-specific abbreviated weekday name specfied by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • culture Object

    Culture information

Returns:

String:

dayOfMonth

(
  • date
  • leadingZero
)
String static

Defined in ../lib/pat.js:1249

Returns a string representing the day of the month specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZero Boolean

    Zero padded result?

Returns:

String:

dayOfYear

(
  • date
  • leadingZeros
)
String static

Defined in ../lib/pat.js:1222

Returns a string representing the day of the year specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZeros Boolean

    Zero padded result?

Returns:

String:

hours

(
  • date
  • leadingZero
  • h12
)
String static

Defined in ../lib/pat.js:1309

Returns the formatted hours specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZero Boolean

    Zero padded result?

  • h12 Boolean

    Hours in [1,12]?

Returns:

String:

milliseconds

(
  • date
  • leadingZeros
)
String static

Defined in ../lib/pat.js:1350

Returns the formatted milliseconds specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZeros Boolean

    Zero padded result?

Returns:

String:

minutes

(
  • date
  • leadingZero
)
String static

Defined in ../lib/pat.js:1326

Returns the formatted minutes specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZero Boolean

    Zero padded result?

Returns:

String:

month

(
  • date
  • leadingZero
)
String static

Defined in ../lib/pat.js:1236

Returns a string representing the month specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZero Boolean

    Zero padded result?

Returns:

String:

monthName

(
  • date
  • culture
)
String static

Defined in ../lib/pat.js:1263

Returns the culture-specific month name specfied by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • culture Object

    Culture information

Returns:

String:

seconds

(
  • date
  • leadingZero
)
String static

Defined in ../lib/pat.js:1338

Returns the formatted seconds specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZero Boolean

    Zero padded result?

Returns:

String:

time

(
  • date
  • leadingZeros
)
String static

Defined in ../lib/pat.js:1404

Returns a string representing the 24h time specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZeros Boolean

    Zero padded time components?

Returns:

String:

time12

(
  • date
  • leadingZeros
  • designator
)
String static

Defined in ../lib/pat.js:1417

Returns a string representing the 12h time specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • leadingZeros Boolean

    Zero padded time components?

  • designator Boolean

    Including time designator (AM/PM)?

Returns:

String:

timeDesignator

(
  • date
  • culture
)
String static

Defined in ../lib/pat.js:1365

Returns a string representing the morning/afternoon designator for the time specified by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • culture Object

    Culture information

Returns:

String:

timezoneOffset

(
  • date
)
String static

Defined in ../lib/pat.js:1379

Returns a string representing the given date's time zone offset from UTC.

Parameters:

  • date Date

    Interpreted as a date with the same timezone as provided by the host OS.

Returns:

String:

weekdayName

(
  • date
  • culture
)
String static

Defined in ../lib/pat.js:1286

Returns the culture-specific weekday name specfied by the given date.

Parameters:

  • date Date

    Interpreted as a UTC value

  • culture Object

    Culture information

Returns:

String:

year

(
  • date
  • [options]
)
String static

Defined in ../lib/pat.js:1165

Returns a string representing the specified year.

Negative years are formatted with the prefix '-' by default. Set the option property bcPrefix or bcPostfix to change the default behavior. Note that setting a non-falsy postfix implies the prefix ''.

The number of digits in the resulting string depends on the option properties maxDigits and leadingZeros. The resulting year is zero padded if maxDigits is greater than the number of year digits and leadingZeros is set to true. Most significant digits of the resulting year are truncated if maxDigits is less than the number of year digits. In that case leading zeros are also truncated except leadingZeros is set to true.

Parameters:

  • date Date

    Interpreted as a UTC value

  • [options] Object optional

    Format options. Default values are:

       {
           bcPrefix: '-',
           bcPostfix: '',
           leadingZeros: false
           maxDigits: number of year digits
       }
    

Returns:

String:

Example:

    var d = new Date('2012-01-01T00:00Z');
    Formatter.date.year(d); //'2012'
    Formatter.date.year(d, {maxDigits:3}); //'12'
    Formatter.date.year(d, {maxDigits:3, leadingZeros:true}); //'012'
    Formatter.date.year(d, {maxDigits:5, leadingZeros:true}); //'02012'

    d = new Date(Date.UTC(-2012, 1));
    Formatter.date.year(d); //'-2012'
    Formatter.date.year(d, {bcPostfix: ' BC.'}); //'2012 BC.'
    Formatter.date.year(d, {bcPrefix: 'BC.'}); //'BC.2012'