# @easepick/datetime
TIP
This package does not need to be installed if you are using @easepick/bundle.
DateTime library for easepick
.
# Quick example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>easepick</title>
<script src="https://cdn.jsdelivr.net/npm/@easepick/datetime@[version.number]/dist/index.umd.min.js"></script>
</head>
<body>
<div id="date-el"></div>
<script>
const DateTime = easepick.DateTime;
const today = new DateTime();
const tomorrow = today.clone().add(1, 'day');
const dateEl = document.getElementById('date-el');
dateEl.innerHTML = `
Today is: ${today.format('DD MMM YYYY')}
<br/>
Tomorrow is: ${tomorrow.format('DD MMM YYYY')}
`;
</script>
</body>
</html>
# DateTime() constructor
Creates a JavaScript DateTime instance that represents a single moment in time.
Using: new DateTime(date, format, lang)
argument | type | default value | description |
---|---|---|---|
date | Date string number | null | Date (opens new window) object or date string or number (unix timestamp). |
format | string | 'YYYY-MM-DD' | Required when you provide date argument as string. Must match a string value for proper parsing. |
lang | string | 'en-US' | Affects month names (MMM , MMMM tokens). |
You can omit all arguments and call new DateTime()
. This will create a DateTime object represents the current date.
# Methods
name | arguments |
---|---|
getWeek | - |
clone | - |
toJSDate | - |
inArray | (array, inclusivity) |
isBetween | (date1, date2, inclusivity) |
isBefore | (date, unit) |
isSameOrBefore | (date, unit) |
isAfter | (date, unit) |
isSameOrAfter | (date, unit) |
isSame | (date, unit) |
add | (duration, unit) |
subtract | (duration, unit) |
diff | (date, unit) |
format | (format, lang) |
# Tokens format
Tokens are case-sensitive.
Token | Output | |
---|---|---|
Day of Month | D | 1 2 … 30 31 |
DD | 01 02 … 30 31 | |
Month | M | 1 2 … 11 12 |
MM | 01 02 … 11 12 | |
MMM | Jan Feb … Nov Dec | |
MMMM | January February … November December | |
Year | YY | 70 71 … 29 30 |
YYYY | 1970 1971 … 2029 2030 | |
Hours (24 hour time) | H | 0 1 … 22 23 |
HH | 01 02 … 22 23 | |
Minutes | m | 1 2 … 58 59 |
mm | 01 02 … 58 59 | |
Seconds | s | 1 2 … 58 59 |
ss | 01 02 … 58 59 |