Skip to content

Commit 00481bb

Browse files
committed
Add Get The Time Components Of A Date as a JavaScript TIL
1 parent 7e2b60e commit 00481bb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1309 TILs and counting..._
13+
_1310 TILs and counting..._
1414

1515
---
1616

@@ -432,6 +432,7 @@ _1309 TILs and counting..._
432432
- [Generate Random Integers](javascript/generate-random-integers.md)
433433
- [Get The Location And Size Of An Element](javascript/get-the-location-and-size-of-an-element.md)
434434
- [Get The Response Status From An Axios Error](javascript/get-the-response-status-from-an-axios-error.md)
435+
- [Get The Time Components Of A Date](javascript/get-the-time-components-of-a-date.md)
435436
- [Get The Time Zone Of The Client Computer](javascript/get-the-time-zone-of-the-client-computer.md)
436437
- [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md)
437438
- [Globally Install Specific Version Of PNPM](javascript/globally-install-specific-version-of-pnpm.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Get The Time Components Of A Date
2+
3+
A `Date` object in JavaScript has several functions available to it for getting
4+
at the time components of that date.
5+
6+
```javascript
7+
> const now = new Date()
8+
undefined
9+
> now
10+
2023-06-14T17:44:06.425Z
11+
> now.getMinutes()
12+
44
13+
> now.getSeconds()
14+
6
15+
> now.getHours()
16+
12
17+
```
18+
19+
For a given `Date` object, you can access the hours with
20+
[`getHours()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours),
21+
the minutes with
22+
[`getMinutes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes),
23+
and the seconds with
24+
[`getSeconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds).
25+
26+
To round things out, there is also
27+
[`getMilliseconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
28+
and
29+
[`getTimezoneOffset()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset).

0 commit comments

Comments
 (0)