-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5103524
commit 177b282
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
const currentDate = new Date(); | ||
|
||
function getDayAbbrev(date) { | ||
const days = [ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
]; | ||
return days[date.getDay()]; | ||
} | ||
|
||
function getMonthAbbrev(date) { | ||
const months = [ | ||
"January", | ||
"February", | ||
"March", | ||
"April", | ||
"May", | ||
"June", | ||
"July", | ||
"August", | ||
"September", | ||
"October", | ||
"November", | ||
"December", | ||
]; | ||
return months[date.getMonth()]; | ||
} | ||
|
||
function getTime(date) { | ||
let hours = date.getHours(); | ||
let minutes = date.getMinutes(); | ||
let period = hours >= 12 ? "PM" : "AM"; | ||
|
||
if (hours === 0) { | ||
hours = 12; | ||
} else if (hours > 12) { | ||
hours -= 12; | ||
} else if (hours === 12) { | ||
period = "PM"; | ||
} | ||
minutes = minutes < 10 ? `0${minutes}` : minutes; | ||
|
||
return `${hours}:${minutes} ${period}`; | ||
} | ||
function getUTCTime(date) { | ||
let hours = date.getUTCHours(); | ||
let minutes = date.getUTCMinutes(); | ||
let period = hours >= 12 ? "PM" : "AM"; | ||
|
||
if (hours === 0) { | ||
hours = 12; | ||
} else if (hours > 12) { | ||
hours -= 12; | ||
} else if (hours === 12) { | ||
period = "PM"; | ||
} | ||
minutes = minutes < 10 ? `0${minutes}` : minutes; | ||
|
||
return `${hours}:${minutes} ${period}`; | ||
} | ||
|
||
|
||
console.log(`Full Date: ${currentDate}`); | ||
console.log(`Day: ${getDayAbbrev(currentDate)}`); | ||
console.log(`Month: ${getMonthAbbrev(currentDate)}`); | ||
console.log(`Date: ${currentDate.getDate()}`); // Built-In | ||
console.log(`Local Year: ${currentDate.getFullYear()}`); | ||
console.log(`UTC Year: ${currentDate.getUTCFullYear()}`); | ||
console.log(`Local Time: ${getTime(currentDate)}`); | ||
console.log(`UTC Time: ${getUTCTime(currentDate)}`); | ||
console.log(`Time Zone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`); |