Created
July 30, 2023 04:03
-
-
Save Asikur22/5297eb1271fffd76484a2f0d97018220 to your computer and use it in GitHub Desktop.
JS Date Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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