Date Objects are created with the new Date() constructor. There are 4 ways to create a new date object.
new Date()
new Date(year, month, day, hour, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)
There are 3 types of JavaScript date input formats:
Type | Example |
---|---|
ISO Date | "2022-02-22"(The International Standard) |
Short Date | "03/22/2022" |
Long Date | "Mar 22 2022" or "22 Mar 2022" |
-
getFullYear()
Get the year as a four digit number (yyyy).
-
getMonth()
Get the month as a number (0-11).
-
getDate()
Get the date as a number (1-31).
-
getHours()
Get the hour (0-23).
-
getMinutes()
Get the minute (0-59).
-
getTime()
Get the time (miliiseconds since 1 January 1970).
-
getDay()
Get the weekday as a number (0-6).
-
Date.now()
It returns the number of milliseconds since 1 January 1970.
-
getSeconds()
Get the second (0-59).
-
getMilliseconds()
Get the millisecond (0-999).
-
setDate()
Set the day as a number (1-31).
-
setfullYear()
Set the year (optionally month and date).
-
setMonth()
Set the month (0-11).
-
setHours()
Set the hour (0-23).
-
setMinutes()
Set the minutes (0-59).
-
setSeconds()
Set the seconds (0-59).
-
setMilliseconds()
Set the milliseconds (0-999).
The JavaScript Math object allows to perform mathematical tasks on numbers. The Math object has no constructor.
-
abs(x)
Returns the absolute value of x.
-
acos(x)
Returns the arccosine of x, in radians.
-
acosh(x)
Returns the hyperbolic arccosine of x.
-
asin(x)
Returns the arcsine of x, in radians.
-
asinh(x)
Returns the hyperbolic arcsine of x.
-
atan(x)
Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians.
-
atan2(y, x)
Returns the arctangent of the quotient of its arguments.
-
atanh(x)
Returns the hyperbolic arctangent of x.
-
cbrt(x)
Returns the cubic root of x.
-
ceil(x)
Returns x, rounded upwards to the nearest integer.
-
cos(x)
Returns the cosine of x (x is in radians).
-
cosh(x)
Returns the hyperbolic cosine of x.
-
exp(x)
Returns the value of Ex.
-
floor(x)
Returns x, rounded downwards to the nearest integer.
-
log(x)
Returns the natural logarithm (base E) of x.
-
max(x, y, z, ..., n)
Returns the number with the highest value.
-
min(x, y, z, ..., n)
Returns the number with the lowest value.
-
pow(x, y)
Returns the value of x to the power of y.
-
random()
Returns a random number between 0 and 1.
-
round(x)
Rounds x to the nearest integer.
-
sign(x)
Returns if x is negative, null or positive (-1, 0, 1).
-
sin(x)
Returns the sine of x (x is in radians).
-
sinh(x)
Returns the square root of x.
-
sqrt(x)
Returns the square root of x.
-
tan(x)
Returns the tangent of an angle.
-
tanh(x)
Returns the hyperbolic tangent of a number.
-
trunc(x)
Returns the integer part of a number (x).