Learn JS #20

JavaScript Get Date Methods


These methods can be used for getting information from a date object:

Method Description
getFullYear() Get the year as a four digit number (yyyy)
getMonth() Get the month as a number (0-11)
getDate() Get the day as a number (1-31)
getHours() Get the hour (0-23)
getMinutes() Get the minute (0-59)
getSeconds() Get the second (0-59)
getMilliseconds() Get the millisecond (0-999)
getTime() Get the time (milliseconds since January 1, 1970)
getDay() Get the weekday as a number (0-6)
Date.now() Get the time. ECMAScript 5.

The getTime() Method

The getTime() method returns the number of milliseconds since January 1, 1970:

Example

const d = new Date();
d.getTime();

The getFullYear() Method

The getFullYear() method returns the year of a date as a four digit number:

Example

const d = new Date();
d.getFullYear();

The getMonth() Method

The getMonth() method returns the month of a date as a number (0-11):

Example

const d = new Date();
d.getMonth();

In JavaScript, the first month (January) is month number 0, so December returns month number 11.

You can use an array of names, and getMonth() to return the month as a name:

Example

const months = ["January""February""March""April""May""June""July""August""September""October""November""December"];

const d = new Date();
let month = months[d.getMonth()];

The getDate() Method

The getDate() method returns the day of a date as a number (1-31):

Example

const d = new Date();
d.getDate();

The getHours() Method

The getHours() method returns the hours of a date as a number (0-23):

Example

const d = new Date();
d.getHours();

The getMinutes() Method

The getMinutes() method returns the minutes of a date as a number (0-59):

Example

const d = new Date();
d.getMinutes();

The getSeconds() Method

The getSeconds() method returns the seconds of a date as a number (0-59):

Example

const d = new Date();
d.getSeconds();

The getMilliseconds() Method

The getMilliseconds() method returns the milliseconds of a date as a number (0-999):

Example

const d = new Date();
d.getMilliseconds();

The getDay() Method

The getDay() method returns the weekday of a date as a number (0-6):

Example

const d = new Date();
d.getDay();

In JavaScript, the first day of the week (0) means “Sunday”, even if some countries in the world consider the first day of the week to be “Monday”

You can use an array of names, and getDay() to return the weekday as a name:

Example

const days = ["Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday"];

const d = new Date();
let day = days[d.getDay()];

Categories

166 Responses

  1. Drug information. Long-Term Effects.
    stromectol cream
    Comprehensive side effect and adverse reaction information. Comprehensive side effect and adverse reaction information.

  2. Get here. drug information and news for professionals and consumers.
    ivermectin syrup
    п»їMedicament prescribing information. Comprehensive side effect and adverse reaction information.

  3. Some are medicines that help people when doctors prescribe. All trends of medicament.
    ivermectin 500mg
    Comprehensive side effect and adverse reaction information. Actual trends of drug.

  4. What side effects can this medication cause? Drug information.
    https://levaquin.science/# can you buy cheap levaquin without insurance
    Get warning information here. Some are medicines that help people when doctors prescribe.

  5. drug information and news for professionals and consumers. All trends of medicament.
    cost nexium price
    Some are medicines that help people when doctors prescribe. Cautions.

  6. Everything information about medication. Learn about the side effects, dosages, and interactions.
    clomid online
    Commonly Used Drugs Charts. What side effects can this medication cause?

  7. Some are medicines that help people when doctors prescribe. Some are medicines that help people when doctors prescribe.
    https://finasteridest.online how to buy generic propecia price
    Medscape Drugs & Diseases. earch our drug database.

  8. Read here. drug information and news for professionals and consumers.
    ed remedies
    Everything information about medication. Some are medicines that help people when doctors prescribe.

  9. Comprehensive side effect and adverse reaction information. Everything information about medication.
    top rated ed pills
    Drug information. drug information and news for professionals and consumers.

  10. Comprehensive side effect and adverse reaction information. Read information now.
    https://canadianfast.online/# buy prescription drugs from canada cheap
    Read information now. Learn about the side effects, dosages, and interactions.

  11. Medicament prescribing information. Comprehensive side effect and adverse reaction information.
    sildenafil gel
    Learn about the side effects, dosages, and interactions. Read now.

  12. Some are medicines that help people when doctors prescribe. Long-Term Effects.
    tadalafil cost india
    п»їMedicament prescribing information. Definitive journal of drugs and therapeutics.

  13. Medscape Drugs & Diseases. Some are medicines that help people when doctors prescribe.
    cialis viagra cocktail
    drug information and news for professionals and consumers. Prescription Drug Information, Interactions & Side.

Leave a Reply

Your email address will not be published. Required fields are marked *