bozdoz
bozdoz

Reputation: 12860

Get epoch timestamp in Grunt JS

I found in the Grunt docs how to format a date in the template:

grunt.template.today('yyyy') // '2014'

from http://gruntjs.com/api/grunt.template

I'm wondering how I can get the epoch. I'm using a text-replace plugin to update a global variable when the files were last changed (using grunt-contrib-watch).

Just not sure how to update the variable with a proper epoch timestamp.

Without a format, template.today does a standard:

Wed Apr 09 2014 13:21:03

Upvotes: 2

Views: 3355

Answers (1)

photoionized
photoionized

Reputation: 5232

Remember that Grunt is just Javascript, you can use:

new Date().getTime();

This will give you the epoch time. Just assign to a variable and pass to the text-replace plugin.

Upvotes: 8

Related Questions