Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tcort/handlebars-dateformat
handlebars date format helper
https://github.com/tcort/handlebars-dateformat
date formatter handlebars
Last synced: 3 months ago
JSON representation
handlebars date format helper
- Host: GitHub
- URL: https://github.com/tcort/handlebars-dateformat
- Owner: tcort
- License: isc
- Created: 2015-11-13T03:32:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-09-30T12:43:01.000Z (over 2 years ago)
- Last Synced: 2024-10-08T22:42:00.107Z (4 months ago)
- Topics: date, formatter, handlebars
- Language: JavaScript
- Size: 41 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# handlebars-dateformat
[handlebars](http://handlebarsjs.com/) date format [helper](http://handlebarsjs.com/block_helpers.html).
## Installation
npm install --save handlebars-dateformat
## Usage
### Register the Helper
handlebars.registerHelper('dateFormat', require('handlebars-dateformat'));
### Call the helper from a template
{{dateFormat date format utc}}
Parameters:
* `date` is a JavaScript [Date](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date) or an instance of [moment](http://momentjs.com/).
* `format` is a string containing the desired format (can be a variable or a literal). Placeholders are defined in the [moment.js docs](http://momentjs.com/docs/#/displaying/).
* `utc` optional boolean (`true` or `false`) to decide whether or not to convert the date to UTC before formatting. Defaults to `false`.## Example
`app.js`:
"use strict";
var hbs = require('hbs');
var express = require('express');hbs.registerHelper('dateFormat', require('handlebars-dateformat'));
var app = express();
app.set('view engine', 'hbs');
app.get('/', function (req, res) {
res.render('index', { now: new Date() });
});app.listen(3000);
`views/index.hbs`:
The server time is: {{dateFormat now "dddd, MMMM Do YYYY, h:mm:ss a"}}
## Testing
npm test
## License
See [LICENSE.md](https://github.com/tcort/handlebars-dateformat/blob/master/LICENSE.md)