Skip to content
"time.h" bindings for Node.js
JavaScript C++ Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


"time.h" bindings for NodeJS.

This module offers simple bindings for the C time.h APIs. It also offers an extended regular Date object with getTimeZone() and setTimeZone() functions, which aren't normally part of JavaScript.


var time = require('time');

// Create a new Date instance
var now = new time.Date();

// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-8

// `.getDate()`, `.getDay()`, `.getHours()`, etc.
// will return values according to UTC-5


Date() -> Date

A special Date constructor that returns a "super" Date instance, that has magic timezone capabilities!

var date = new time.Date();

date.setTimeZone(timezone) -> Undefined

Sets the timezone for the Date instance. Calls to getHours(), getDays(), getMinutes(), etc. will be relative to the timezone specified. This will throw an Error if information for the desired timezone could not be found.


date.getTimeZone() -> String

Returns a String containing the currently configured timezone for the date instance.

 // "America/Argentina/San_Juan"

time() -> Number

Binding for time(). Returns the number of seconds since Jan 1, 1900 UTC. These two are equivalent:

 // 1299827226
Math.floor( / 1000);
 // 1299827226

tzset(timezone) -> Object

Binding for tzset(). Sets up the timezone information that localtime() will use based on the specified timezone variable, or the current process.env.TZ value if none is specified. Returns an Object containing information about the newly set timezone, or throws an Error if no timezone information could be loaded for the specified timezone.

 // { tzname: [ 'PST', 'PDT' ],
 //   timezone: 28800,
 //   daylight: 1 }

localtime(Number) -> Object

Binding for localtime(). Accepts a Number with the number of seconds since the Epoch (i.e. the result of time()), and returns a "broken-down" Object representation of the timestamp, according the the currently configured timezone (see tzset()).

 // { seconds: 38,
 //   minutes: 7,
 //   hours: 23,
 //   dayOfMonth: 10,
 //   month: 2,
 //   year: 111,
 //   dayOfWeek: 4,
 //   dayOfYear: 68,
 //   isDaylightSavings: false,
 //   gmtOffset: -28800,
 //   timezone: 'PST' }
Something went wrong with that request. Please try again.