Socket
Socket
Sign inDemoInstall

timezonedate

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    timezonedate

A JavaScript Date alternative that is specific to a given timezone other than the current machine's timezone.


Version published
Weekly downloads
3
Maintainers
1
Install size
241 kB
Created
Weekly downloads
 

Readme

Source

TimeZoneDate

A JavaScript Date alternative that is specific to a given timezone other than the current machine's timezone.

Installation

npm install timezonedate

Environment Support

TimeZoneDate has been tested in Node, IE9+, Chrome, Firefox, and Opera.

Usage

// CommonJS
var TimeZoneDate = require('timezonedate');
// AMD
require(['timezonedate'], function(TimeZoneDate) { ... });
// Script Tag
var TimeZoneDate = window.TimeZoneDate;

API

function TimeZoneDate(offset[, initialDate])
offset

type: Number

There are two ways to specify a timezone offset.

The easiest is by passing in the hours relative to UTC. So if you want to specify the timezone one hour behind UTC, you would pass in -1. For one hour ahead of UTC, you would pass in 1.

The other way to specify the timezone is to pass in what the result of new Date().getTimezoneOffset() would be if it were run in the target timezone. For example, if your system clock is set to UTC-1, new Date().getTimezoneOffset() will be 60. If you are in UTC+1, the result will be -60. Check out the MDN getTimezoneOffset documentation for more info.

initialDate

type: Date or String

If a Date object is passed in, the TimeZoneDate will be set to the same moment, rather than the same time. For example:

// Assume the current machine is set to UTC-1
var dateInUTCMinus1 = new Date('1/1/2014 12:00:00');
var dateInUTCPlus1 = new TimeZoneDate(1, dateInUTCMinus1);

dateInUTCMinus1.valueOf() === dateInUTCPlus1.valueOf();
// true

dateInUTCMinus1.toString();
// Wed Jan 01 2014 12:00:00 GMT-0100

dateInUTCPlus1.toString();
// Wed Jan 01 2014 14:00:00 GMT+0100

If a string is passed in, the TimeZoneDate will be set to that date/time. For example:

// Assume the current machine is set to UTC-1
var dateInUTCMinus1 = new Date('1/1/2014 12:00:00');
var dateInUTCPlus1 = new TimeZoneDate(1, '1/1/2014 12:00:00');

dateInUTCMinus1.valueOf() === dateInUTCPlus1.valueOf();
// false

dateInUTCMinus1.toString();
// Wed Jan 01 2013 12:00:00 GMT-0100

dateInUTCPlus1.toString();
// Wed Jan 01 2013 12:00:00 GMT+0100

If the initialDate parameter is omitted, it is the equivalent of passing in new Date().

The rest of the API is exactly the same as the native Date object.

Keywords

FAQs

Last updated on 20 Dec 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc