Answers for "js get date time"

45

javascript get time

// these are the most useful ones IMO
var time = new Date();
time.getDate(); // returns value 1-31 for day of the month
time.getDay(); //returns value 0-6 for day of the week
time.getFullYear(); //returns a 4 digit value for the current year
time.getHours(); //returns value 0-23 for the current hour
time.getMinutes(); //returns value 0-59 for the current minute of the hour
time.getSeconds(); //returns value 0-59 for current second of the minute
time.getMilliseconds(); //returns value 0-999 for current ms of the second
time.getTime(); //returns date as ms since Jan 1, 1970
time.toDateString(); //returns a string (e.g. "Fri May 9 2020")
time.toLocaleString(); //returns date and time (e.g. "9/12/2015, 6:08:25 PM")
time.toLocaleTimeString(); //returns time (e.g. "6:08:25 PM")
time.toLocaleDateString(); //returns date (e.g. "9/12/2015")
Posted by: Guest on May-15-2020
31

js date methods

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)
d.getDay();  //Get the weekday as a number (0-6)
d.Date.now();	//Get the time. ECMAScript 5.
d.setDate()	//Set the day as a number (1-31)
d.setFullYear()	//Set the year (optionally month and day)
d.setHours()	//Set the hour (0-23)
d.setMilliseconds()	//Set the milliseconds (0-999)
d.setMinutes()	//Set the minutes (0-59)
d.setMonth()	//Set the month (0-11)
d.setSeconds()	//Set the seconds (0-59)
d.setTime()	//Set the time (milliseconds since January 1, 1970)
Posted by: Guest on May-02-2020
8

javascript current date time

var today = new Date().toLocaleDateString(undefined, {
    day: '2-digit',
    month: '2-digit',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
})
Posted by: Guest on April-07-2020
10

get date javascript

getDate() in javascript only returns the day as number (1-31)

Example
var d = new Date();
document.getElementById("demo").innerHTML = d.getDate();

Output:
22

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.
Posted by: Guest on April-22-2020
3

get date in javascript

function getTodayDate() {
    let d = new Date();
    return d;
}

console.log(getTodayDate());

//2020-12-06T09:53:14.105Z
Posted by: Guest on December-06-2020
6

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
Posted by: Guest on April-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language