Skip to content

Instantly share code, notes, and snippets.

@Torkiwi
Torkiwi / date.js
Created July 24, 2023 10:21 — forked from Ebugo/date.js
Replicate PHP's native date() formatting in JavaScript for many common format types
/**
* Return a formated string from a date Object mimicking PHP's date() functionality
*
* @param {string} format "Y-m-d H:i:s" or similar PHP-style date format string
* @param {* | null} date Date Object, Datestring, or milliseconds
*
*/
function date(format, date) {
if (!date || date === "") {
date = new Date();