Registry / productivity / php-date

php-date

JSON →
library4.0.1jsnpmunverified

A JavaScript library that mimics PHP's date() function for formatting Date objects. Current stable version is 4.0.1. Ships TypeScript definitions, works in Node.js and all modern browsers including IE11. Key differentiators: small size (1.2KB gzipped), supports almost all PHP date format tokens except timezone identifiers (e, T), and provides a UTC variant date.UTC(). Active development with regular releases.

npm install php-date
INSTALL
IMPORT
SIG · PHP-DATE
P
php-date
productivityjavascriptv4.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import date from 'php-date'
const date = require('php-date')
ESM default import is the primary usage pattern. CommonJS require is also supported but ESM is recommended for modern projects.
date
const date = require('php-date')
import { date } from 'php-date'
The package exports a default function; named import is not available. CommonJS require returns the function directly.
date.UTC
import date from 'php-date'; date.UTC(formatter, date)
import { UTC } from 'php-date'
date.UTC is a property on the default export, not a separate named export. It formats in UTC timezone.

Demonstrates basic formatting with PHP-style tokens, UTC variant, and defaulting to current time.

import date from 'php-date'; const releaseDate = new Date(2016, 9, 18); // Format like PHP's date() console.log(date('d.m.Y', releaseDate)); // 18.10.2016 console.log(date('F jS Y', releaseDate)); // October 18th 2016 // Using UTC variant console.log(date.UTC('Y-m-d H:i:s', new Date())); // e.g., 2025-01-15 12:00:00 // Without a date argument (defaults to now) console.log(date('l, jS F Y')); // e.g., Wednesday, 15th January 2025
Debug
Known issues
gotchaTimezone tokens 'e' and 'T' are not supported and will return an empty string.
fix
Use alternative methods like Intl.DateTimeFormat to get timezone identifiers, or avoid using those tokens.
affects: >=1.0.0
deprecatedCommonJS require('php-date') is still supported but ESM imports are preferred and may become default in future major versions.
fix
Migrate to import date from 'php-date'
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: date is not a function
Using named import instead of default import.
fix
Use import date from 'php-date'
Uncaught ReferenceError: date is not defined
Using require with CommonJS in an ESM-only environment.
fix
Use import date from 'php-date' or configure bundler to handle CommonJS.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
php-daterequiredNone - no runtime dependencies, but requires a Date object from the runtime.
Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
php-date — npm install php-date · libregistry