mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-08-31 01:14:08 +08:00
fix(curriculum): correct Date object constructor explanation (#69212)
This commit is contained in:
+16
-6
@@ -34,21 +34,31 @@ console.log(now);
|
||||
|
||||
For the time, it is using the military time format, so `14:30` is `2:30 PM`. `GMT-0700` is the timezone offset, and `Pacific Daylight Time` is the timezone name.
|
||||
|
||||
You can also pass in a specific date and time to the `Date` object by providing the year, month, day, hour, minute, second, and millisecond values as arguments.
|
||||
|
||||
Here is an example of creating a new `Date` object with a specific date and time:
|
||||
Here is an example of creating a new `Date` object with a specific date string:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
const specificDate = new Date("July 4, 1776 12:00:00");
|
||||
const dateFromString = new Date("July 4, 1776 12:00:00");
|
||||
|
||||
console.log(specificDate);
|
||||
console.log(dateFromString);
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
This is useful when you need to work with a specific date and time rather than the current date and time. The input always needs to be a string, and the format should be recognizable by the `Date` object.
|
||||
You can also pass in a specific date and time to the `Date` object by providing the year, month, day, hour, minute, second, and millisecond values as arguments:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
const dateFromArguments = new Date(1776, 6, 4, 12, 0, 0, 0);
|
||||
|
||||
console.log(dateFromArguments);
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
This is useful when you need to work with a specific date and time rather than the current date and time.
|
||||
|
||||
To get the current date and time, you can use the `Date.now()` method, which returns the number of milliseconds since `January 1, 1970, 00:00:00 UTC`. This is known as the Unix epoch time.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user