Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including nunjucks-date with all npm packages installed. Try it out:

// Import nunjucks var nunjucks = require('nunjucks'); // Import the plugin var nunjucksDate = require('nunjucks-date'); var moment = require('moment'); // Define a custom default date format. Any valid format works. // The date format defaults to "YYYY" // http://momentjs.com/docs/#/displaying/format/ nunjucksDate.setDefaultFormat('MMMM Do YYYY, h:mm:ss a'); // Initialize your Nunjucks enironment var env = new nunjucks.Environment(); // Pass the environment & a custom filter name nunjucksDate.install(env, 'mySpecialDateFilter'); // Print out environment filters to ensure filter is present console.log('Now your filter should be listed here: ', env.filters); // Example Usage var dateStringTest = '1995-12-25'; var currentDate = env.renderString( ` Present: {{ present | mySpecialDateFilter}} & Past: {{ past }} `, { present: moment(), past: moment(dateStringTest).fromNow() } ); console.log('currentDate', currentDate);

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nunjucks-date v1.5.0

Plugin for nunjucks of momentjs format date

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free