Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/swashcap/amd-date

AMD-compatible JavaScript date printer.
https://github.com/swashcap/amd-date

Last synced: about 2 months ago
JSON representation

AMD-compatible JavaScript date printer.

Awesome Lists containing this project

README

        

# AMD Date

_AMD-compatible JavaScript date printer._

Use [Ruby-like string-to-time formats](http://rubyinrails.com/2013/09/strftime-format-time-in-ruby/) to get a JavaScript date as a string.

## Usage

1. Use [RequireJS](http://requirejs.org) or a similar module loader.
2. Add _index.js_ to your project.
3. Load this script in a `define` or `require` (see [RequireJS’s docs](http://requirejs.org/docs/api.html#define)):

```javascript
require(['path/to/amd-date/index'], function(DateHelper) {
...
});
```

4. 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, '

%B %d %Y

');

console.log(myFormattedDate);
// =>

May 14 2014


```

## Format Reference

* `%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

## ToDos

* Fix `%Z` timezone output
* Internationalization
* Add tests _(help needed!)