Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ben-ng/tz2tz
Shorthand for common timezone operations
https://github.com/ben-ng/tz2tz
Last synced: 21 days ago
JSON representation
Shorthand for common timezone operations
- Host: GitHub
- URL: https://github.com/ben-ng/tz2tz
- Owner: ben-ng
- Created: 2015-01-15T13:51:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-30T02:29:17.000Z (almost 10 years ago)
- Last Synced: 2024-10-11T14:04:20.052Z (28 days ago)
- Language: JavaScript
- Size: 199 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/ben-ng/tz2tz.svg?branch=master)](https://travis-ci.org/ben-ng/tz2tz)
## Disclaimer
Honestly I'm just writing this so that I can require it without relative file paths in my projects.
If you find it useful, great. Otherwise, like all open-source software, expect zero support.
I will happily merge PRs though :)
## API
```js
// I recommend 'z' because 't' is a common temp var name
var z = require('tz2tz')
, timestamp = Date.now()// Parse the timestamp in the timezone then output it in the moment-style format specified
z(timestamp, 'America/Los_Angeles', 'ddd MMM D')// Shorthandy goodness
// Thu Jan 15
// Uses 'ddd MMM D' as format
z.getDate(timestamp, 'America/Los_Angeles')// 6:05AM
// Uses 'h:mmA' as format
z.getTime(timestamp, 'America/Los_Angeles')// 6:05AM 1/15/15
z.getShort(timestamp, 'America/Los_Angeles')// Thu, Jan 15, 2015 6:05 AM
// Uses preferred locale format
z.getFull(timestamp, 'America/Los_Angeles')// Thursday
z.getDay(timestamp, 'America/Los_Angeles')// 6 (integer)
z.getHours(timestamp, 'America/Los_Angeles')// 5 (integer)
z.getMinutes(timestamp, 'America/Los_Angeles')// Change the shorthand constants
z.constants.timeFormat = 'h:mm a'
```## Is That All?
Yeah that's it. But seriously, if you had to do this hundreds of times, you would want something like this too.