datef
datef is a Javascript date formatting library, both for browser and node.js.
Features
- Can output: year, full year, month, day, hour, minutes, seconds, milliseconds and timezone — both zero padded and not
- Simple localization
- Built-in formats and easyly extensible
- Doesn't mess with built-in prototypes
- Acts as node.js and requirejs/amd module, and have
.noConflict
method in case no module system is present (e.g. plain browser environment) - No external dependencies
- Contains predefined formats for some ISO8601 date and time representation
- Thoroughly annotated with jsdoc, so if your IDE/editor supports it, you may never need interrupt yourself from code
Usage
Node.js
npm install datef
var datef = ;;
Require.js
require;
Browser
Basic usage
; // "13.08.13"; // second argument is optional; datef takes Date.now() if no date is provided var d = ;d;; // "13.08.2045"
Languages
Node.js
dateflang'ru';; // 13 августа
Require.js
require ;
Browser
Custom formatters
// predefined formatsdatef; // ['ISODate','ISOTime','ISODateTime','ISODateTimeTZ']; // "2013-08-13T15:01:29 -04:00" // defining your own simple formatdatef;; // "13.8.13" // defining your own format with i10ndatef;; // "August 13, Tuesday"dateflang'ru';; // "Вторник, 13 августа"dateflang'uk';; // "13 жніўня"
Cleaning global namespace
This is similar to Backbone.noConflict()
…
Tokens
Full list of tokens possible in format string include:
- YYYY: 4-digit year
- YY: last 2 digit of year
- MMMM: full name of month
- MMM: short name of month
- MM: ISO8601-compatible number of month (i.e. zero-padded) in year (with January being 1st month)
- M: number of month in year without zero-padding (with January being 1st month)
- DDD: full name of day
- DD: short name of day
- D: min name of day
- dd: zero-padded number of day in month
- d: number of day in month
- HH: zero-padded 24 hour time
- H: 24 hour time
- hh: zero-padded 12 hour time
- h: 12 hour time
- mm: zero-padded minutes
- m: minutes
- ss: zero-padded seconds
- s: seconds
- ff: zero-padded milliseconds, 3 digits
- f: milliseconds
- A: AM/PM
- a: am/pm
- ZZ: time-zone in ISO8601-compatible basic format (i.e. "-0400")
- Z: time-zone in ISO8601-compatible extended format (i.e. "-04:00")