js getdate code example
Example 1: get date javascript
var d= new Date();
d.getFullYear();//Get the year as a four digit number (yyyy)
d.getMonth();//Get the month as a number (0-11)
d.getDate();//Get the day as a number (1-31)
d.getHours();//Get the hour (0-23)
d.getMinutes();//Get the minute (0-59)
d.getSeconds();//Get the second (0-59)
d.getMilliseconds();//Get the millisecond (0-999)
d.getTime();//Get the time (milliseconds since January 1, 1970)
Example 2: javascript get date
let date = new Date(); //actual time in miliseconds
let string = date.toString();
// expected output: Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)
// if you need more power: date-fns.js or moment.js
Example 3: get date in javascript
function getTodayDate() {
let d = new Date();
return d;
}
console.log(getTodayDate());
//2020-12-06T09:53:14.105Z
Example 4: javascript getdate
var d=new Date();
d.getDate(); //returns the day of the month (from 1 to 31)