In JavaScript, when we talk about time, weβre concerned about 4 things:
- Hours
- Minutes
- Seconds
- Milliseconds
The Date object has four methods that give you each of the 4 things:
getHours: Gets hours (0-23) according to local time.getMinutes: Gets minutes (0-59) according to local time.getSeconds: Gets seconds (0-59) according to local time.getMilliseconds: Gets milliseconds (0-999) according to local time.
Loosely speaking, local time means the current time in your timezone. Your local time will be different from mine. Weβll talk about timezones in the next lesson.
Exercise
Creating a custom time format is much easier than creating a custom date format. Create the following time formats:
08:34:23.456(Hours:minutes:seconds.milliseconds)8:34am(or8:34pm, depending on the time of the day)
Welcome! Unfortunately, you donβt have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson