BrightDates
Timezone aware date parsing and formatting
Test Bench
There is a live demo on CodePen which you can fiddle with. Once the CodePen page loads, open browser's development console and follow the instructions.
Methods
All date and datetime methods accept an optional timezone overide as the last argument
brightDates.setTimezone(tz)
Set the default timezone
brightDates;
brightDates.getTimezone
Get the set timezone
brightDates; // Europe/LondonbrightDates;brightDates; // Canada/Eastern
brightDates.date(date, timezone)
Convert a string or native date into a timezone aware date moment
brightDates; // 2016-10-13T00:00:00Z (moment) brightDates; // 2016-10-13T00:00:00Z (moment)
brightDates.dateTime(dateTimeInput, timezone)
Convert a string or native date into a timezone aware datetime moment
brightDatesdateTime2016 11 13 21 4 3; // 2016-10-13T21:04:03Z (moment) brightDatesdateTime'2017-10-13T21:04:03Z'; // 2016-10-13T21:04:03Z (moment)
brightDates.dateAndTime(dateInput, timeInput, timezone = userTimezone)
Convert individual date and time elements to a datetime moment
brightDates; // 2016-10-13T01:43:00Z (moment) brightDates; // 2016-10-13T01:43:00Z (moment)
brightDates.today
Get a moment of today
brightDates;
brightDates.formatDate(date, format)
Format a string or native date, returns ISO 8601 if no format is specified.
- short: 'DD/MM/YYYY'
- friendly: 'ddd Do MMM YYYY'
- friendlyShort: 'ddd Do MMM'
- timezone: 'zz'
- offset: 'Z'
brightDates; // 13/10/2016
brightDates.formatDateTime
Format a string or native date, returns ISO 8601 if no format is specified.
- short: 'YYYY-MM-DD'
- friendly: 'dddd Do MMM YYYY'
- friendlyShort: 'ddd Do MMM'
- time: 'hh:mm'
- timezone: 'zz'
- offset: 'Z'
- datetime: 'YYYY-MM-DD hh:mm'
brightDates; // 01:43
moment static methods
The following static methods from moment are also exported: