
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@bitchcraft/timestamp
Advanced tools
Output RFC3339 / ISO8601 String from Date
$ yarn add @bitchcraft/timestamp
$ npm install -P @bitchcraft/timestamp
timestampFromDate(date: Date, tz: Timezone): string
Outputs an RFC3339 / ISO8601 string from a date. The date is converted to the specified output TZ, or UTC (Z / +0000) if not provided.
| @param | Type | Default value | Description |
|---|---|---|---|
| date | Date | required | |
| timezone | Timezone | new Timezone('Z') | the TZ for the output string |
import { timestampFromDate, Timezone } from '@bitchcraft/timestamp';
const utcTimezone = new Timezone('Z');
const currentDate = new Date();
const currentUtcTimestamp = timestampFromDate(currentDate, utcTimezone);
console.log(`The current UTC timestamp is ${currentUtcTimestamp}.`);
var { timestampFromDate, Timezone } = require('@bitchcraft/timestamp');
var utcTimezone = new Timezone('Z');
var currentDate = new Date();
var currentUtcTimestamp = timestampFromDate(currentDate, utcTimezone);
console.log('The current UTC timestamp is %s.', currentUtcTimestamp);
new Timezone(tz: string): Timezone
A timezone helper class.
Parameters
| @param | Type | Description |
|---|---|---|
| tz | string | Timezone string, e. g. 'Z', 'GMT+3', '-0230'. Default value is '+0000' |
Properties and methods
| Return type | Description | ||
|---|---|---|---|
| @prop | value | string | ISO timezone string, e. g. 'Z', '+0800', '-1130' |
| @prop | hours | number (unsigned int) | integer representation of the hours part of the timezone. See toNumber() to get an integer representation of the timezone. |
| @prop | minutes | number (unsigned int) | integer representation of the minutes part of the timezone. See toNumber() to get an integer representation of the timezone. |
| @prop | sign | number (signed int) | number representation of the prefix of the timenzone. 1 for positive, 0 for UTC and -1 for negative timezone offset. |
| @prop | prefix | string | string represenationg of the prefix, e. g. '+', 'Z' or '-' |
| @method | toString() | string | returns value |
| @method | toNumber(option: string, invertSign: boolean) | number (signed int) | returns value as a number. The scale is provided in option (defaults to 'MINUTES'). Set invertSign to true for sign symmetry with Date.getTimezoneOffset() (defaults to false). Valid values for option are: 'MILLENIA', 'CENTURIES', 'DECADES', 'YEARS', 'QUARTERS', 'MONTHS', 'WEEKS', 'DAYS', 'HOURS', 'MINUTES', 'SECONDS', 'MILLISECONDS'. |
| @static | fromNumber(offset: number, invertSign: boolean) | Timezone | Create a timezone instance from a number (in minutes) |
| @static | getPrefixFor(timezoneString: string) | string | Return cleaned prefix from timezone string. returns '+' for '+', '-' for '-'/'–'/'—' and 'Z' for everything else |
| @static | getPrefixForSign(sign: number) | string | Return string prefix for number. See @prop prefix |
| @static | getSignForPrefix(timezoneString: string) | number | Return number sign for string. See @prop sign |
Please file issues in Github
We are open for PRs. Please respect to the linting rules.
Timestamp is free software und the BSD-3-Clause (see LICENSE.md).
FAQs
RFC3339 / ISO8601 String from Date
We found that @bitchcraft/timestamp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.