js datetime code example
Example 1: js date methods
var d= new Date();
d.getFullYear();
d.getMonth();
d.getDate();
d.getHours();
d.getMinutes();
d.getSeconds();
d.getMilliseconds()
d.getTime();
d.getDay();
d.Date.now();
d.setDate()
d.setFullYear()
d.setHours()
d.setMilliseconds()
d.setMinutes()
d.setMonth()
d.setSeconds()
d.setTime()
Example 2: datetime to date javascript
var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
var dateString = date + "-" +(month + 1) + "-" + year;
Example 3: javascript date
var currentDate = new Date();
var dateFromTimeStamp= new Date(1560807962);
var dateFromString = new Date('December 17, 1995 03:24:00');
var dateFromYearMonthDay = new Date(2018, 11, 26, 0, 0, 0, 0);
Example 4: js get day month year
const d = new Date();
d.getMonth() + 1;
d.getDate();
d.getFullYear();
Example 5: js time
Pulling Date and Time Values
getDate()
Get the day of the month as a number (1-31)
getDay()
The weekday as a number (0-6)
getFullYear()
Year as a four digit number (yyyy)
getHours()
Get the hour (0-23)
getMilliseconds()
The millisecond (0-999)
getMinutes()
Get the minute (0-59)
getMonth()
Month as a number (0-11)
getSeconds()
Get the second (0-59)
getTime()
Get the milliseconds since January 1, 1970
getUTCDate()
The day (date) of the month in the specified date according to universal time (also available for
day, month, fullyear, hours, minutes etc.)
parse
Parses a string representation of a date, and returns the number of milliseconds since January
Example 6: dates in javascript
new Date();
Date.now();
new Date(year, month, day hours, minutes, seconds, milliseconds)