mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Get The Time Components Of A Date as a JavaScript TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1309 TILs and counting..._
|
_1310 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -432,6 +432,7 @@ _1309 TILs and counting..._
|
|||||||
- [Generate Random Integers](javascript/generate-random-integers.md)
|
- [Generate Random Integers](javascript/generate-random-integers.md)
|
||||||
- [Get The Location And Size Of An Element](javascript/get-the-location-and-size-of-an-element.md)
|
- [Get The Location And Size Of An Element](javascript/get-the-location-and-size-of-an-element.md)
|
||||||
- [Get The Response Status From An Axios Error](javascript/get-the-response-status-from-an-axios-error.md)
|
- [Get The Response Status From An Axios Error](javascript/get-the-response-status-from-an-axios-error.md)
|
||||||
|
- [Get The Time Components Of A Date](javascript/get-the-time-components-of-a-date.md)
|
||||||
- [Get The Time Zone Of The Client Computer](javascript/get-the-time-zone-of-the-client-computer.md)
|
- [Get The Time Zone Of The Client Computer](javascript/get-the-time-zone-of-the-client-computer.md)
|
||||||
- [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md)
|
- [Globally Install A Package With Yarn](javascript/globally-install-a-package-with-yarn.md)
|
||||||
- [Globally Install Specific Version Of PNPM](javascript/globally-install-specific-version-of-pnpm.md)
|
- [Globally Install Specific Version Of PNPM](javascript/globally-install-specific-version-of-pnpm.md)
|
||||||
|
|||||||
29
javascript/get-the-time-components-of-a-date.md
Normal file
29
javascript/get-the-time-components-of-a-date.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Get The Time Components Of A Date
|
||||||
|
|
||||||
|
A `Date` object in JavaScript has several functions available to it for getting
|
||||||
|
at the time components of that date.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> const now = new Date()
|
||||||
|
undefined
|
||||||
|
> now
|
||||||
|
2023-06-14T17:44:06.425Z
|
||||||
|
> now.getMinutes()
|
||||||
|
44
|
||||||
|
> now.getSeconds()
|
||||||
|
6
|
||||||
|
> now.getHours()
|
||||||
|
12
|
||||||
|
```
|
||||||
|
|
||||||
|
For a given `Date` object, you can access the hours with
|
||||||
|
[`getHours()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours),
|
||||||
|
the minutes with
|
||||||
|
[`getMinutes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes),
|
||||||
|
and the seconds with
|
||||||
|
[`getSeconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds).
|
||||||
|
|
||||||
|
To round things out, there is also
|
||||||
|
[`getMilliseconds()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
|
||||||
|
and
|
||||||
|
[`getTimezoneOffset()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset).
|
||||||
Reference in New Issue
Block a user