Dino Geek, try to help you

How to handle date and time in JavaScript?


JavaScript has a built-in `Date` object that you can use to create and manipulate dates and times.

You can create a new `Date` object as follows:

```
// create a new date object with current date and time
let now = new Date();
console.log(now); // output: current date and time
```

You can also create a new `Date` object from a specific date and time:

```
// create a new date object with specific date
let specificDate = new Date(‘2015-03-25T12:00:00’);
console.log(specificDate); // output: Wed Mar 25 2015 12:00:00 GMT+0000 (Coordinated Universal Time)
```

The `Date` object provides several methods for getting and setting individual parts of a date and time, such as the year, month, day, hours, minutes, seconds, and milliseconds.

Here are some examples:

```
let now = new Date();

// get parts of the date
console.log(now.getFullYear()); // output: current year
console.log(now.getMonth()); // output: current month (0-based, 0 = January)
console.log(now.getDate()); // output: current day of the month
console.log(now.getHours()); // output: current hour
console.log(now.getMinutes()); // output: current minutes
console.log(now.getSeconds()); // output: current seconds
console.log(now.getMilliseconds()); // output: current milliseconds

// set parts of the date
now.setFullYear(2020); // set the year to 2020
now.setMonth(0); // set the month to January
now.setDate(1); // set the day of the month to 1
now.setHours(0); // set the hour to 0
now.setMinutes(0); // set the minutes to 0
now.setSeconds(0); // set the seconds to 0
now.setMilliseconds(0); // set the milliseconds to 0
```

It’s important to note that JavaScript date and time is based on a time value that is milliseconds since 01 January, 1970 UTC.

Also, JavaScript dates are calculated in milliseconds. For example, 1 day is 86,400,000 milliseconds.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use