get date and time in javascript code example
Example 1: javascript get time
var time = new Date();
time.getDate();
time.getDay();
time.getFullYear();
time.getHours();
time.getMinutes();
time.getSeconds();
time.getMilliseconds();
time.getTime();
time.toDateString();
time.toLocaleString();
time.toLocaleTimeString();
time.toLocaleDateString();
Example 2: today's time in javascript
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
Example 3: javascript get current time
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
Example 4: how to use current data in javascript
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
Example 5: javascript get date without time
function WithoutTime(dateTime) {
var date = new Date(dateTime.getTime());
date.setHours(0, 0, 0, 0);
return date;
}
Example 6: get date javascript
var d= new Date();
d.getFullYear();
d.getMonth();
d.getDate();
d.getHours();
d.getMinutes();
d.getSeconds();
d.getMilliseconds();
d.getTime();