DateTimeUtils Class
Utility functions work working with dates and times.
Item Index
Methods
- formatDate static
- formatTime static
- normalize static
- parseDate static
- parseDate static
- parseTime static
Properties
- AM_STRING static
- CLOCK_DISPLAY_TYPE static
- DATE_FIELD_DELIMITER static
- DAY_POSITION static
- MONTH_POSITION static
- PM_STRING static
- TIME_FIELD_DELIMITER static
- YEAR_POSITION static
Methods
formatDate
-
date
Format the date portion of a Date object.
Parameters:
-
date
Mixedstring (returned as-is), Date, milliseconds, or object specifying day,month,year
Returns:
formatted date, using positions and delimiter
formatTime
-
time
Format the time portion of a Date object.
Parameters:
-
time
Mixedstring (returned as-is), Date, milliseconds, or object specifying hour,minute
Returns:
formatted time, using delimiter
normalize
-
input
-
default_time
Normalizes the given object by converting date_str into year,month,day, converting time_str into hour,minute (or adding in hour,minute from default_time), and adding date (instanceof Date). Individual fields take precedence over strings.
If input is a Date object, then the result contains a breakdown of the values.
Parameters:
-
input
Date | Number | ObjectCan be specified either as instance of Date, a number specifying milliseconds since midnight Jan 1, 1970, or as an object defining date_str or year,month,day and (optional) either time_str or hour,minute.
-
default_time
ObjectDefault hour and minute to use if input only has date.
Returns:
normalized object defining date and time
parseDate
-
date
Inverse of formatDate(). Extracts year, month, and day from the string. The values are normalized to fall inside the default ranges.
Parameters:
-
date
Stringstring from DateTimeUtils.formatDate()
Returns:
year,month,day, or null
parseDate
-
date
-
delimiater
-
year_pos
-
month_pos
-
day_pos
Utility for parsing a date string that is not formatted based on the Y.DateTime configuration.
Parameters:
-
date
Stringstring from DateTimeUtils.formatDate()
-
delimiater
Stringdelimiter between the date fields
-
year_pos
Numberposition of the year in the string representation: 1,2,3
-
month_pos
Numberposition of the month in the string representation: 1,2,3
-
day_pos
Numberposition of the day in the string representation: 1,2,3
Returns:
normalized object defining date
parseTime
-
time
Inverse of formatTime(). Extracts hour and minute from the string. Throws an error if hour is outside [0,23] or minute is outside [0,59].
Parameters:
-
time
Stringstring from DateTimeUtils.formatTime()
Returns:
hour,minute, or null
Properties
AM_STRING
String
static
Antemeridian string.
Default: "AM"
CLOCK_DISPLAY_TYPE
Number 12 or 24
static
How hours should be displayed to the user by classes in the DateTime family: 12hr or 24hr. (Internal values are always 24hr.) This is global because your app should be consistent about how it displays times.
Default: 24
DATE_FIELD_DELIMITER
String
static
Delimiter of fields in a string representation of a date.
Default: "-"
DAY_POSITION
Number
static
Position of the day in a string representation of a date: 1,2,3
Default: 3
MONTH_POSITION
Number
static
Position of the month in a string representation of a date: 1,2,3
Default: 2
PM_STRING
String
static
Postmeridian string.
Default: "PM"
TIME_FIELD_DELIMITER
String
static
Delimiter of fields in a string representation of a time.
Default: ":"
YEAR_POSITION
Number
static
Position of the year in a string representation of a date: 1,2,3
Default: 1