Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/swashcap/amd-date
- Owner: swashcap
- Created: 2014-05-15T00:57:08.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-16T03:28:36.000Z (almost 11 years ago)
- Last Synced: 2024-11-10T03:37:52.189Z (3 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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!)