DateUtils
On this page
DateUtils ⇐Class
- DateUtils()
- DAYS_IN_WEEK
- DAYS_IN_YEAR
- MONTH_IN_YEAR
- ONE_SECOND :
number
- ONE_MINUTE :
number
- ONE_HOUR :
number
- ONE_DAY :
number
- ONE_WEEK :
number
- FORMAT_TOKEN :
RegExp
- TIMEZONE_REGEX :
RegExp
- TIMEZONE_CLIP_REGEX :
RegExp
- compare(firstDate, secondDate) ⇒
number
- isBefore(firstDate, secondDate) ⇒
boolean
- isAfter(firstDate, secondDate) ⇒
boolean
- isBetween(date, start, end) ⇒
boolean
- diff(firstDate, secondDate, [diffYear]) ⇒
Object
- relativeTimeByNow(date) ⇒
number
- addMilliseconds(date, value)
- addSeconds(date, value)
- addMinutes(date, value)
- addHours(date, value)
- addDays(date, value)
- addWeeks(date, value)
- addMonths(date, value)
- addYears(date, value)
removeDays(date, days)removeHours(date, hours)removeMinutes(date, minutes)- add(date, config)
- isLeapYear(year) ⇒
boolean
- getDayOfYear(date) ⇒
number
- getWeekOfYear(target, [weekstart]) ⇒
number
- getDaysInMonth([month], [year]) ⇒
number
- isSameDay(firstDate, secondDate) ⇒
boolean
- isNextDay(firstDate, secondDate) ⇒
boolean
- isPreviousDay(firstDate, secondDate) ⇒
boolean
- isToday(date) ⇒
boolean
- isYesterday(date) ⇒
boolean
- isTomorrow(date) ⇒
boolean
- moveToDayOfWeek(date, day, [orient])
- today() ⇒
Date
- tomorrow() ⇒
Date
- yesterday() ⇒
Date
- now() ⇒
Date
- clone(date) ⇒
Date
- clearTime(date)
- floor30(date)
- floor15(date)
- formatTime(time, mask) ⇒
string
- formatDate(date, mask, utc) ⇒
string
DateUtils ⇐ Class
Class
Deprecated
Kind: global class
Extends: Class
DateUtils ⇐Class
- new DateUtils()
- .DAYS_IN_WEEK
- .DAYS_IN_YEAR
- .MONTH_IN_YEAR
- .ONE_SECOND :
number
- .ONE_MINUTE :
number
- .ONE_HOUR :
number
- .ONE_DAY :
number
- .ONE_WEEK :
number
- .FORMAT_TOKEN :
RegExp
- .TIMEZONE_REGEX :
RegExp
- .TIMEZONE_CLIP_REGEX :
RegExp
- .compare(firstDate, secondDate) ⇒
number
- .isBefore(firstDate, secondDate) ⇒
boolean
- .isAfter(firstDate, secondDate) ⇒
boolean
- .isBetween(date, start, end) ⇒
boolean
- .diff(firstDate, secondDate, [diffYear]) ⇒
Object
- .relativeTimeByNow(date) ⇒
number
- .addMilliseconds(date, value)
- .addSeconds(date, value)
- .addMinutes(date, value)
- .addHours(date, value)
- .addDays(date, value)
- .addWeeks(date, value)
- .addMonths(date, value)
- .addYears(date, value)
.removeDays(date, days).removeHours(date, hours).removeMinutes(date, minutes)- .add(date, config)
- .isLeapYear(year) ⇒
boolean
- .getDayOfYear(date) ⇒
number
- .getWeekOfYear(target, [weekstart]) ⇒
number
- .getDaysInMonth([month], [year]) ⇒
number
- .isSameDay(firstDate, secondDate) ⇒
boolean
- .isNextDay(firstDate, secondDate) ⇒
boolean
- .isPreviousDay(firstDate, secondDate) ⇒
boolean
- .isToday(date) ⇒
boolean
- .isYesterday(date) ⇒
boolean
- .isTomorrow(date) ⇒
boolean
- .moveToDayOfWeek(date, day, [orient])
- .today() ⇒
Date
- .tomorrow() ⇒
Date
- .yesterday() ⇒
Date
- .now() ⇒
Date
- .clone(date) ⇒
Date
- .clearTime(date)
- .floor30(date)
- .floor15(date)
- .formatTime(time, mask) ⇒
string
- .formatDate(date, mask, utc) ⇒
string
DateUtils()
This static class represents DateUtils. It provides several tools to work with Dates
DAYS_IN_WEEK
number of days in one week
Kind: static property of DateUtils
DAYS_IN_YEAR
number of days in one year (omitting leap years)
Kind: static property of DateUtils
MONTH_IN_YEAR
number of months in one year
Kind: static property of DateUtils
ONE_SECOND : number
Value for one second in millisecond.
Kind: static constant of DateUtils
ONE_MINUTE : number
Value for one minute in millisecond.
Kind: static constant of DateUtils
ONE_HOUR : number
value for one hour in millisecond.
Kind: static constant of DateUtils
ONE_DAY : number
value for one day in millisecond.
Kind: static constant of DateUtils
ONE_WEEK : number
value for one week day in millisecond.
Kind: static constant of DateUtils
FORMAT_TOKEN : RegExp
Regex for format replacement
Kind: static constant of DateUtils
TIMEZONE_REGEX : RegExp
Regex for timezone replacement
Kind: static constant of DateUtils
TIMEZONE_CLIP_REGEX : RegExp
Regex for timezone clip replacement
Kind: static constant of DateUtils
compare(firstDate, secondDate) ⇒ number
Compare the first date against second date.
Kind: static method of DateUtils
Returns: number
- -1 : if firstDate < secondDate
0 : if firstDate === secondDate
1 : if firstDate > secondDate
NaN : if firstDate or secondDate is an illegal date
Param | Type | Description |
---|---|---|
firstDate | Date | the first date |
secondDate | Date | the second date |
isBefore(firstDate, secondDate) ⇒ boolean
Check if the secondDate date is before the firstDate
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
firstDate | Date | Date to compare |
secondDate | Date | Date to compare |
isAfter(firstDate, secondDate) ⇒ boolean
Check if the secondDate date is after the firstDate
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
firstDate | Date | Date to compare |
secondDate | Date | Date to compare |
isBetween(date, start, end) ⇒ boolean
Check if the date is between the start and end dates.
Kind: static method of DateUtils
Warning: Returns false if start date is after end date
Param | Type |
---|---|
date | Date |
start | Date |
end | Date |
diff(firstDate, secondDate, [diffYear]) ⇒ Object
Gap between two date.
Kind: static method of DateUtils
Returns: Object
- Like: {sec: {number}, min: {number}, hour: {number}, day: {number}, year: {}}
Param | Type | Description |
---|---|---|
firstDate | Date | Date to compare |
secondDate | Date | Date to compare |
[diffYear] | Boolean | If true, year will be counted. (false by default) - Based of 365 days |
relativeTimeByNow(date) ⇒ number
Return a number that tell how many milliseconds is passed from now since the date, or how many milliseconds it remains to reach the date from now.
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
addMilliseconds(date, value)
Add or subtract milliseconds to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of milliseconds to add. Could be negative to subtract some. |
addSeconds(date, value)
Add or subtract seconds to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of seconds to add. Could be negative to subtract some. |
addMinutes(date, value)
Add or subtract minutes to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of minutes to add. Could be negative to subtract some. |
addHours(date, value)
Add or subtract hours to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of hours to add. Could be negative to subtract some. |
addDays(date, value)
Add or subtract days to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of days to add. Could be negative to subtract some. |
addWeeks(date, value)
Add or subtract weeks to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of weeks to add. Could be negative to subtract some. |
addMonths(date, value)
Add or subtract months to date.
Kind: static method of DateUtils
Warning: this implementation remove days if the new month doesn’t have the matching day number (30/31 => 28/29/30)
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of months to add. Could be negative to subtract some. |
addYears(date, value)
Add or subtract years to date.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
value | number | the number of years to add. Could be negative to subtract some. |
removeDays(date, days)
Use addDays function with a negative parameter instead of that function.
Subtraction of a duration in days
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
days | number | duration in days |
removeHours(date, hours)
Use addHours function with a negative parameter instead of that function.
Subtraction of a duration in hours
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
hours | number | duration in hours |
removeMinutes(date, minutes)
Use addMinutes function with a negative parameter instead of that function.
Subtraction of a duration in minutes
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
minutes | number | duration in minutes |
add(date, config)
Add or subtract several components of a datetime
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
config | Object |
config.milliseconds | number |
config.seconds | number |
config.minutes | number |
config.hours | number |
config.days | number |
config.weeks | number |
config.months | number |
config.years | number |
isLeapYear(year) ⇒ boolean
Is year in param a leap one.
Kind: static method of DateUtils
See
- https://en.wikipedia.org/wiki/Leap_year#Algorithm
- http://www.ecma-international.org/ecma-262/6.0/#sec-year-number
Param | Type |
---|---|
year | Date | number |
getDayOfYear(date) ⇒ number
Return the number of day since the start of the date year.
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
getWeekOfYear(target, [weekstart]) ⇒ number
Return the date week number.
Kind: static method of DateUtils
See
- https://en.wikipedia.org/wiki/Week#Week_numbering
- https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
Param | Type | Description |
---|---|---|
target | Date | |
[weekstart] | number | (0: sunday, 1: Monday,...). Monday by default (as ISO standard) |
getDaysInMonth([month], [year]) ⇒ number
Get the number of days in given month of given year.
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
[month] | number | 0-based month number. Current mont of current year if not specified |
[year] | number | current year if not specified |
isSameDay(firstDate, secondDate) ⇒ boolean
Are firstDate and secondDate the same day?
Kind: static method of DateUtils
Param | Type |
---|---|
firstDate | Date |
secondDate | Date |
isNextDay(firstDate, secondDate) ⇒ boolean
Is secondDate the next day after firstDate?
Kind: static method of DateUtils
Param | Type |
---|---|
firstDate | Date |
secondDate | Date |
isPreviousDay(firstDate, secondDate) ⇒ boolean
Is secondDate the next day before firstDate?
Kind: static method of DateUtils
Param | Type |
---|---|
firstDate | Date |
secondDate | Date |
isToday(date) ⇒ boolean
Is current date today ?
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
isYesterday(date) ⇒ boolean
Is given date yesterday ?
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
isTomorrow(date) ⇒ boolean
Is given date Tomorrow ?
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
moveToDayOfWeek(date, day, [orient])
Move given date to next or last occurrence of given day of week
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | |
day | number | Wanted day (0: sunday, 1: monday, 2: tuesday,...) |
[orient] | number | If 1, get next occurrence of the day, else if -1 get previous occurrence of the day. Default value : 1. |
today() ⇒ Date
Returns a Date object corresponding to today at 00:00:00
Kind: static method of DateUtils
tomorrow() ⇒ Date
Returns a Date object corresponding to tomorrow at 00:00:00
Kind: static method of DateUtils
yesterday() ⇒ Date
Returns a Date object corresponding to yesterday at 00:00:00
Kind: static method of DateUtils
now() ⇒ Date
Return the current Date.
Kind: static method of DateUtils
clone(date) ⇒ Date
Clone the Date.
Kind: static method of DateUtils
Returns: Date
- Cloned date
Param | Type |
---|---|
date | Date |
clearTime(date)
Reset hours minutes seconds and milliseconds to 0.
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
floor30(date)
Round at the lowest half hour
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
floor15(date)
Round at the lowest quarter hour.
Kind: static method of DateUtils
Param | Type |
---|---|
date | Date |
formatTime(time, mask) ⇒ string
Format a number corresponding to a time in millisecond to a readable format following some ISO 8601
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
time | number | time in milliseconds |
mask | string | Define the way the string will be formatted |
Example (Mask options)
H Hours; no leading zero for single-digit hours
HH Hours; leading zero for single-digit hours
M Minutes; no leading zero for single-digit minutes.
MM Minutes; leading zero for single-digit minutes.
s Seconds; no leading zero for single-digit seconds.
ss Seconds; leading zero for single-digit seconds.
l Milliseconds; gives 3 digits.
L Milliseconds; gives 2 digits.
'...', "..." Literal character sequence. Surrounding quotes are removed.
formatDate(date, mask, utc) ⇒ string
Format a date based on some ISO 8601
Kind: static method of DateUtils
Param | Type | Description |
---|---|---|
date | Date | The date to format |
mask | string | Define the way the string will be formatted |
utc | boolean | if true, convert local time to UTC |
Example (Mask options)
d Day of the month as digits; no leading zero for single-digit days.
dd Day of the month as digits; leading zero for single-digit days.
m Month as digits; no leading zero for single-digit months.
mm Month as digits; leading zero for single-digit months.
yy Year as last two digits; leading zero for years less than 10.
yyyy Year represented by four digits.
h Hours; no leading zero for single-digit hours (12-hour clock).
hh Hours; leading zero for single-digit hours (12-hour clock).
H Hours; no leading zero for single-digit hours (24-hour clock).
HH Hours; leading zero for single-digit hours (24-hour clock).
M Minutes; no leading zero for single-digit minutes.
MM Minutes; leading zero for single-digit minutes.
o GMT/UTC timezone offset, e.g. -0500 or +0230.
s Seconds; no leading zero for single-digit seconds.
ss Seconds; leading zero for single-digit seconds.
l Milliseconds; gives 3 digits.
L Milliseconds; gives 2 digits.
t Lowercase, single-character time marker string: a or p.
tt Lowercase, two-character time marker string: am or pm.
T Uppercase, single-character time marker string: A or P.
TT Uppercase, two-character time marker string: AM or PM.
Z US timezone abbreviation, e.g. EST or MDT. For non-US timezones, the GMT/UTC offset is returned, e.g. GMT-0500
'...', "..." Literal character sequence. Surrounding quotes are removed.
UTC: Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.