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 set-now with all npm packages installed. Try it out:

var setNow = require("set-now")

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

set-now v2.0.2

Travel through time with Date.setNow()


Adds Date.setNow() to JavaScript's global Date object.

Build Status

This is useful for making tests deterministic. Wind back the clock to a time in the past (or in the future).


npm install set-now



new Date() // Thu Mar 17 2016 08:00:00 GMT-0400 (EDT) // 1458216000000

// wait 1 second
setTimeout(function () {
  new Date() // Thu Mar 17 2016 08:00:01 GMT-0400 (EDT)
  Date.setNow() // reset the time back to normal
  new Date() // today's actual date
}, 1000)

Date.setNow( [time] )

Set the clock to the specified time.

  • time {String} (optional) The time you want it to be. If time is not specified, the clock will be reset to the actual time.
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