@o2htechnology/datetime
v1.0.2
Published
```bash npm i @o2htechnology/datetime ```
Downloads
3
Readme
Install Package
npm i @o2htechnology/datetime
Usage
// import library using required
const datetime = required('@o2htechnology/datetime');
const date = new Date();
// returns DD-MM-YYYY date format
const format = datetime(date).formate('DD-MM-YYYY');
// returns day of week like Tuesday
const day = datetime(date).day();
Format options
| Format | result | | ------------------------- | ---------------------------------------------------------------- | | D | 1 2 ... 30 31 (day of month) | | DD | 1 2 ... 30 31 (2 letter of day of month) | | DDD | 1 2 ... 364 365 (day of year) | | DDDD | 001 002 ... 364 365 (day of year) | | d | 0 1 ... 5 6 (day of week) | | dd | Su Mo ... Fr Sa (2 letter day) | | dd | Sun Mon ... Fri Sat (3 letter day) | | dddd | Sunday Monday ... Friday Saturday | | M | 1 2 ... 11 12 (Month) | | MM | 01 02 ... 11 12 (Month) | | MMM | Jan Feb ... Nov Dec (Month string) | | MMMM | January February ... November December (Month string) | | y, yy, yyy, yyyy, YYYY, Y | 4 digit year | | YY | 2 digit year | | h | 1 2 ... 11 12 (12 hour) | | H | 0 1 ... 22 23 (24 hour) | | hh | 01 02 ... 11 12 (12 hour) | | HH | 00 01 ... 22 23 (24 hour) | | m | 0 1 ... 58 59 (minute) | | mm | 00 01 ... 58 59 (minute) | | s | 0 1 ... 58 59 (Second) | | ss | 00 01 ... 58 59 (Second) | | a,A | Post or ante meridiem | | x | Unix Millisecond Timestamp | | X | Unix Timestamp | | Q | 1 2 3 4 (Quarter number) | | Qo | 1st 2nd 3rd 4th (Quarter number with ordinary suffix) | | Mo | 1st 2nd ... 11th 12th (Month number with ordinary suffix) | | Do | 1st 2nd ... 30th 31st (Day of month number with ordinary suffix) | | DDDo | 1st 2nd ... 364th 365th (Day of year) | | do | 0th 1st ... 5th 6th (Day of week) | | w | 1 2 ... 52 53 (week of year) | | wo | 1st 2nd ... 52nd 53rd (week of year) | | ww | 01 02 ... 52 53 (Week of year) |
Methods
** .utc() **
datetime().utc();
.utc() is utc mode. Ambiguous input is assumed to be UTC. Unambiguous input is adjusted to UTC.
** .tz(timezone) **
e.g
datetime().tz('Asia/Kolkata');
does parsing in given time zone
** .add(amount, unit) **
Mutates the original datetime by adding time.
datetime().add(7, 'days');
unit : It is a number, which you want to add in date
| Amounts | | ------------ | | years | | quarters | | months | | weeks | | days | | hours | | minutes | | seconds | | milliseconds |