javascript get current day of month code example

Example 1: js get date day month year

var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();

newdate = year + "/" + month + "/" + day;

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: javascript get current day of month

new Date().getDate();//gets day of month (1-31)

Example 4: js get day month year

const d = new Date();

d.getMonth() + 1;	// Month	[mm]	(1 - 12)
d.getDate();		// Day		[dd]	(1 - 31)
d.getFullYear();	// Year		[yyyy]

Example 5: javascript get day of year from date

//Month -> 0= Jan, 11=Dec | myDate = 6 Dec 2019 10:45
var myDate = new Date(2019, 11, 06, 10, 45);
var dayInYear = Math.floor((myDate - new Date(myDate.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24));

Tags:

Misc Example