{"id":41720,"library":"php-date-formatter","title":"PHP Date Formatter","description":"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.","status":"maintenance","version":"1.3.7","language":"javascript","source_language":"en","source_url":"https://github.com/kartik-v/php-date-formatter","tags":["javascript"],"install":[{"cmd":"npm install php-date-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add php-date-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add php-date-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { DateFormatter } from 'php-date-formatter';","symbol":"DateFormatter","correct":"var formatter = new DateFormatter();"},{"note":"formatDate is a prototype method, not static. You must instantiate DateFormatter first.","wrong":"DateFormatter.formatDate(date, format);","symbol":"formatDate","correct":"formatter.formatDate(date, format);"},{"note":"The third parameter 'lang' is optional but recommended for locale-specific date strings. Defaults to 'en'.","wrong":"formatter.guessDate(dateStr, format); // missing lang leads to undefined behavior","symbol":"guessDate","correct":"formatter.guessDate(dateStr, format, lang);"}],"quickstart":{"code":"// Load the library (assumes in browser via script tag)\nvar formatter = new DateFormatter();\n\n// Format a date\nvar now = new Date();\nvar formatted = formatter.formatDate(now, 'Y-m-d H:i:s');\nconsole.log(formatted); // e.g., '2025-04-03 14:30:00'\n\n// Parse a date string\nvar dateStr = '03/04/2025';\nvar format = 'd/m/Y';\nvar parsed = formatter.guessDate(dateStr, format);\nconsole.log(parsed.toString()); // e.g., 'Thu Apr 03 2025 ...'\n\n// Another example with custom format\nvar result = formatter.formatDate(now, 'l, F jS Y');\nconsole.log(result); // e.g., 'Thursday, April 3rd 2025'","lang":"javascript","description":"Demonstrates usage of DateFormatter to format a JavaScript Date object and parse a date string using PHP date formats."},"warnings":[{"fix":"Consider using a modern library like Luxon or date-fns if you need modules.","message":"The library uses global DateFormatter; no module support (ESM/CommonJS).","severity":"deprecated","affected_versions":"<=1.3.7"},{"fix":"Always validate input string matches expected format before calling guessDate.","message":"guessDate does not throw error on invalid input; returns null or incorrect Date silently.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Be aware that output will be in local time zone. For UTC, wrap with Date's UTC methods.","message":"Time zone handling is based on browser's local time zone; no timezone support for parsing.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Update any custom code that assumed jQuery is required; the library now works standalone.","message":"Removed jQuery dependency in v1.3.2; code may break if relying on old global jQuery usage.","severity":"breaking","affected_versions":">=1.3.2"},{"fix":"Avoid using these format characters or test thoroughly.","message":"PHP format characters like 'I' (DST) and 'Z' (timezone offset) are not fully supported.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"search_vec":"'1.3.7':25 '2016':28 '2018':32 'april':27,31 'browser':84 'cadenc':88 'class':37 'consist':73 'convert':44 'date':2,12,46,59,74 'date/time':17 'dateformatt':36 'depend':80 'extern':79 'format':9,18,50,60,75 'formatd':41 'formatt':3 'guessdat':43 'ideal':64 'javascript':6,70,97 'last':29 'latest':21 'librari':7,92 'like':40 'low':90 'luxon':55 'mainten':95 'make':62 'method':39 'mode':96 'moment.js':53 'must':71 'node.js':86 'object':47 'pars':11 'php':1,15,49,58,68 'php-style':14 'project':66 'provid':34 'releas':26,87 'share':72 'specifi':61 'stabl':22 'standalon':5 'string':19,51 'style':16 'unlik':52 'updat':30 'use':13,57 'version':23 'work':82","created_at":"2026-06-04T18:53:46.936869+00:00","updated_at":"2026-06-04T18:53:46.936869+00:00","problems":[{"fix":"Use const DateFormatter = require('php-date-formatter');","cause":"Using import { DateFormatter } from 'php-date-formatter' in Node.js without proper require.","error":"TypeError: DateFormatter is not a constructor"},{"fix":"Ensure php-date-formatter.min.js is loaded before your script.","cause":"Script not loaded or loaded after usage in browser.","error":"ReferenceError: DateFormatter is not defined"},{"fix":"Always convert input to Date object: new Date(dateStr) or new Date(timestamp).","cause":"Calling formatDate without a valid Date object (passing string or number).","error":"date.replace is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/kartik-v/php-date-formatter","github":"https://github.com/kartik-v/php-date-formatter","docs":null,"changelog":null,"pypi":null,"npm":"php-date-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["productivity"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}