Getting the time

Hey ,

I'm thrilled to help you learn JavaScript. Unfortunately, you've landed on a page where you cannot access with your current purchase.

Please upgrade (use this link) access this content.

I'm super eager to help you learn more!

Getting the time

In JavaScript, when we talk about time, we’re concerned about 4 things:

  1. Hours
  2. Minutes
  3. Seconds
  4. Milliseconds

The Date object has four methods that give you each of the 4 things:

  1. getHours: Gets hours (0-23) according to local time.
  2. getMinutes: Gets minutes (0-59) according to local time.
  3. getSeconds: Gets seconds (0-59) according to local time.
  4. 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:

  1. 08:34:23.456 (Hours:minutes:seconds.milliseconds)
  2. 8:34am (or 8:34pm, depending on the time of the day)