date ported to javascript.
php's date function is pretty nice for formatting dates. since a lot of php developers use it, it would be nice if it can be used in javascript as well!
npm install --save phpdate
// TZ is America/Los_Angeles (DST)
'use strict'
const { date, gmdate } = require('phpdate')
console.log(date('Y-m-d H:i:s')) // => 2016-02-27 17:23:50
console.log(gmdate('Y-m-d H:i:s')) // => 2016-02-28 02:23:50
their are a few differences from php's implementation.
format
is the output format of the date. date
can be an instance of javascript's Date
object. this differs from php, because php's date function takes an integer to specify the time to format.
identical to date
, but will always use UTC/GMT for the time zone