Answers for "javascript date methods"

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
29

javascript 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)
Posted by: Guest on July-23-2019
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
0

JavaScript Date methods

const date = new Date();

console.log(date.getFullYear()); // Output: 2023
console.log(date.getMonth()); // Output: 2 (March is month 2)
console.log(date.getDate()); // Output: 25
console.log(date.getDay()); // Output: 6 (Saturday is day 6)
console.log(date.getHours()); // Output: 11
console.log(date.getMinutes()); // Output: 50
console.log(date.getSeconds()); // Output: 31
console.log(date.getMilliseconds()); // Output: 553
console.log(date.getTime()); 
// Output: 1679722523432 (time in milliseconds since January 1, 1970)
Posted by: Raja MS on January-12-2024

Code answers related to "Javascript"

Browse Popular Code Answers by Language