Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Created July 30, 2023 04:03
Show Gist options
  • Save Asikur22/5297eb1271fffd76484a2f0d97018220 to your computer and use it in GitHub Desktop.
Save Asikur22/5297eb1271fffd76484a2f0d97018220 to your computer and use it in GitHub Desktop.
JS Date Format
function currentServerDate() {
let dateWithTimeZone = new Date().toLocaleString( "en-US", {timeZone: "<?php echo wp_timezone_string(); ?>"} );
let d = new Date( dateWithTimeZone );
var year = d.getFullYear();
var month = (
"00" + (
d.getMonth() + 1
)
).slice( - 2 );
var day = (
"00" + d.getDate()
).slice( - 2 );
var hours = (
"00" + d.getHours()
).slice( - 2 );
var minutes = (
"00" + d.getMinutes()
).slice( - 2 );
var seconds = (
"00" + d.getSeconds()
).slice( - 2 );
// return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + ' AM'; // Y-m-d h:i:s
return year + "-" + month + "-" + day; // Y-m-d
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment