handlebars-dateformat

1.1.3 • Public • Published

handlebars-dateformat

handlebars date format helper.

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 or an instance of moment.
  • format is a string containing the desired format (can be a variable or a literal). Placeholders are defined in the moment.js docs.
  • 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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.3
    2,366
    • latest

Version History

Package Sidebar

Install

npm i handlebars-dateformat

Weekly Downloads

2,408

Version

1.1.3

License

ISC

Unpacked Size

5.93 kB

Total Files

7

Last publish

Collaborators

  • tcort