Last active
June 16, 2022 23:43
-
-
Save 0187773933/af8cc0931db053bc07e67a3a30389458 to your computer and use it in GitHub Desktop.
Get Common Time String in Javascript
This file contains hidden or 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
const MonthNames = [ "JAN" , "FEB" , "MAR" , "APR" , "MAY" , "JUN" , "JUL" , "AUG" , "SEP" , "OCT" , "NOV" , "DEC" ]; | |
function get_time_string() { | |
let today = new Date(); | |
const milliseconds = String( today.getMilliseconds() ).padStart( 3 , "0" ); | |
today = new Date( today.toLocaleString( "en-US" , { timeZone: "America/New_York" } ) ); | |
const day = String( today.getDate() ).padStart( 2 , "0" ) ; | |
const month = MonthNames[ today.getMonth() ]; | |
const year = today.getFullYear(); | |
const hours = String( today.getHours() ).padStart( 2 , "0" ); | |
const minutes = String( today.getMinutes() ).padStart( 2 , "0" ); | |
const seconds = String( today.getSeconds() ).padStart( 2 , "0" ); | |
const result = `${hours}:${minutes}:${seconds}.${milliseconds}`; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment