Registry / productivity / php-date-formatter

php-date-formatter

JSON →
library1.3.7jsnpmunverified

A standalone JavaScript library for formatting and parsing dates using PHP-style date/time format strings. The latest stable version is 1.3.7 (released April 2016, last updated April 2018). It provides a DateFormatter class with methods like formatDate and guessDate, converting between Date objects and PHP format strings. Unlike moment.js or Luxon, it uses PHP date format specifiers, making it ideal for projects where PHP and JavaScript must share consistent date formats. It has no external dependencies and works in browsers and Node.js. Release cadence is low; the library is in maintenance mode.

npm install php-date-formatter
INSTALL
IMPORT
SIG · PHP-DATE-FORMATTER
P
php-date-formatter
productivityjavascriptv1.3.7
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.

DateFormatter
var formatter = new DateFormatter();
import { DateFormatter } from 'php-date-formatter';
The library exports a global DateFormatter constructor. In Node.js, use require('php-date-formatter') or assign to a variable. There is no ES module export.
formatDate
formatter.formatDate(date, format);
DateFormatter.formatDate(date, format);
formatDate is a prototype method, not static. You must instantiate DateFormatter first.
guessDate
formatter.guessDate(dateStr, format, lang);
formatter.guessDate(dateStr, format); // missing lang leads to undefined behavior
The third parameter 'lang' is optional but recommended for locale-specific date strings. Defaults to 'en'.

Demonstrates usage of DateFormatter to format a JavaScript Date object and parse a date string using PHP date formats.

// Load the library (assumes in browser via script tag) var formatter = new DateFormatter(); // Format a date var now = new Date(); var formatted = formatter.formatDate(now, 'Y-m-d H:i:s'); console.log(formatted); // e.g., '2025-04-03 14:30:00' // Parse a date string var dateStr = '03/04/2025'; var format = 'd/m/Y'; var parsed = formatter.guessDate(dateStr, format); console.log(parsed.toString()); // e.g., 'Thu Apr 03 2025 ...' // Another example with custom format var result = formatter.formatDate(now, 'l, F jS Y'); console.log(result); // e.g., 'Thursday, April 3rd 2025'
Debug
Known issues
deprecatedThe library uses global DateFormatter; no module support (ESM/CommonJS).
fix
Consider using a modern library like Luxon or date-fns if you need modules.
affects: <=1.3.7
gotchaguessDate does not throw error on invalid input; returns null or incorrect Date silently.
fix
Always validate input string matches expected format before calling guessDate.
affects: >=1.0
gotchaTime zone handling is based on browser's local time zone; no timezone support for parsing.
fix
Be aware that output will be in local time zone. For UTC, wrap with Date's UTC methods.
affects: >=1.0
breakingRemoved jQuery dependency in v1.3.2; code may break if relying on old global jQuery usage.
fix
Update any custom code that assumed jQuery is required; the library now works standalone.
affects: >=1.3.2
gotchaPHP format characters like 'I' (DST) and 'Z' (timezone offset) are not fully supported.
fix
Avoid using these format characters or test thoroughly.
affects: >=1.0
Errors
Common errors & fixes
TypeError: DateFormatter is not a constructor
Using import { DateFormatter } from 'php-date-formatter' in Node.js without proper require.
fix
Use const DateFormatter = require('php-date-formatter');
ReferenceError: DateFormatter is not defined
Script not loaded or loaded after usage in browser.
fix
Ensure php-date-formatter.min.js is loaded before your script.
date.replace is not a function
Calling formatDate without a valid Date object (passing string or number).
fix
Always convert input to Date object: new Date(dateStr) or new Date(timestamp).
Upgrade
Version history
1.3.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
php-date-formatter — npm install php-date-formatter · libregistry