Interface IDateToStringOptions

The IDateToStringOptions interface describes a set of options to use when converting a standard Date object to a string using the dateToString , or the dateTimeToString method from the DateUtils class. The precedence orders for the options are: useTodayYesterdayAndTomorrow -> useWeekdayIfThisWeek -> omitYearIfCurrentOne -> useLongDateFormat and alwaysIncludeTime -> includeTimeIfThisWeek -> includeTimeIfToday .

Index

Properties

Optional alwaysIncludeTime

alwaysIncludeTime: boolean

Specifies whether to always include the time in the resulting string when converting the Date object (e.g. May 15, 4:17 PM) This option takes precedence over includeTimeIfThisWeek .

Example

If includeTimeIfToday is true and now contains a Date object equivalent to Monday, March 8, 2017, then:

  • If the Date object to convert is equivalent to 2010/03/08 17:23:11, the resulting string is 3/8/2010, 5:23 PM.

Default value is false.

Optional includeTimeIfThisWeek

includeTimeIfThisWeek: boolean

Specifies whether to include the time in the resulting string when converting the Date object (e.g. May 15, 4:17 PM) if the date to convert within a week from now . This option takes precedence over includeTimeIfToday .

Examples

If includeTimeIfToday is true and now contains a Date object equivalent to Monday, March 8, 2017, then:

  • If the Date object to convert is equivalent to 2017/03/08 17:23:11, the resulting string is 3/8/2017, 5:23 PM.

  • If the Date object to convert is equivalent to 2017/03/09 17:23:11, the resulting string is 3/9/2017 ,5:23 PM.

Default value is true.

Optional includeTimeIfToday

includeTimeIfToday: boolean

Specifies whether to include the time in the resulting string when converting the Date object (e.g. May 15, 4:17 PM) if the date to convert is equivalent to now .

Examples

If includeTimeIfToday is true and now contains a Date object equivalent to Monday, March 8, 2017, then:

  • If the Date object to convert is equivalent to 2017/03/08 17:23:11, the resulting string is 3/8/2017, 5:23 PM.

  • If the Date object to convert is equivalent to 2017/03/09 17:23:11, the resulting string is 3/9/2017.

Default value is true.

Optional now

now: Date

Contains a standard Date object that specifies the current date and time.

Default value is undefined.

Optional omitYearIfCurrentOne

omitYearIfCurrentOne: boolean

Specifies whether to omit the year from the resulting string when converting the Date object, if the year is the current one. This option takes precedence over useLongDateFormat .

Examples

  • If the Date object to convert is equivalent to September 22, 2017, the resulting string does not contain the year (e.g., September 22).

  • If the Date object to convert is equivalent to September 22, 2016, the resulting string contains the year (e.g., September 22, 2016).

Default value is true.

Optional predefinedFormat

predefinedFormat: string

Specifies a custom date format (e.g., dd/MM/yyyy), regardless of browser locale or any other option.

This option uses the following syntax. All examples use the April 5th, 2018 14:15:34 time.

  • yyyy: full length year (e.g., 2018)
  • yy: short length year (e.g., 18)
  • MMMM: month name (e.g., April)
  • MMM: shortened month name (e.g., Apr)
  • MM: month number (e.g., 04)
  • M: single digit month number for months before October (e.g., 4)
  • dddd: day name (e.g., Thursday)
  • ddd: shortened day name (e.g., Thu)
  • dd: day number (e.g., 05)
  • d: single digit day for days before the 10th (e.g., 5)
  • hh: hour, in the 24-hour format (e.g., 14)
  • h: hour, in the 12-hour format (e.g., 2)
  • mm: minutes (e.g., 15)
  • ss: seconds (e.g., 34)

Optional useLongDateFormat

useLongDateFormat: boolean

Specifies whether to format the resulting string in the long date format (e.g., Friday, August 04, 2017).

Default value is false.

Optional useTodayYesterdayAndTomorrow

useTodayYesterdayAndTomorrow: boolean

Specifies whether to convert the Date object to the localized version of Today, Yesterday, or Tomorrow, if possible. This option takes precedence over useWeekdayIfThisWeek .

Examples

If useTodayYesterdayAndTomorrow is true, and now contains a Date object equivalent to March 8, 2017, then:

  • If the Date object to convert contains a value equivalent to March 7, 2017, the resulting string is the localized version of Yesterday.

  • If the Date object to convert contains a value equivalent to March 8, 2017, the resulting string is the localized version of Today.

  • If the Date object to convert contains a value equivalent to March 9, 2017, the resulting string is the localized version of Tomorrow.

Default value is true.

Optional useWeekdayIfThisWeek

useWeekdayIfThisWeek: boolean

Specifies whether to convert the Date object to the localized version of the corresponding day of the week, if the date to convert is part of the current week. This option takes precedence over omitYearIfCurrentOne .

Examples

If useWeekdayIfThisWeek is true and now contains a Date object equivalent to Monday, March 8, 2017, then:

  • If the date to convert is equivalent to Saturday, March 6, 2017, the resulting string is the localized version of Last Saturday.

  • If the date to convert is equivalent to Thursday, March 11, 2017, the resulting string is the localized version of Next Thursday.

Default value is true.

Hierarchy

  • IDateToStringOptions