AMD-compatible JavaScript date printer.
Use Ruby-like string-to-time formats to get a JavaScript date as a string.
- Use RequireJS or a similar module loader.
- Add index.js to your project.
- Load this script in a
define
orrequire
(see RequireJS’s docs):
```javascript
require(['path/to/amd-date/index'], function(DateHelper) {
...
});
```
- Inside your module, use the
formatDate
method by passing it a date and desired output format:
```javascript
var myDate = new Date();
var myFormattedDate = DateHelper.formatDate(myDate, '<h1>%B %d <small>%Y</small></h1>');
console.log(myFormattedDate);
// => <h1>May 14 <small>2014<small></h1>
```
%H
: Hour (24)%I
: Hour (12)%M
: Minutes%S
: Seconds%Y
: Year%m
: Month%d
: day%w
: Week day%a
: Week day name (short)%A
: Week day name (full)%b
: Month name (short)%B
: Month name (full)%y
: Year (without century)%Z
: Time zone%p
: AM/PM
- Fix
%Z
timezone output - Internationalization
- Add tests _(help needed!)