JavaScript Date Methods in Geogebra
//JavaScript Date Methods
var d = new Date();
var d = new Date(2018, 11, 24, 10, 33, 30, 0);
var d = new Date(2018, 11, 24, 10, 33, 30);
var d = new Date(2018, 11, 24, 10, 33);
var d = new Date(2018, 11, 24, 10);
var d = new Date(2018, 11, 24);
var d = new Date(2018, 11);
var d = new Date(2018);
var d = new Date(99, 11, 24);
var d = new Date(9, 11, 24);
var d = new Date("July 11, 2020 11:13:00");
var d = new Date(0);
var d = new Date(100000000000);
var d = new Date(-100000000000);
var d = new Date(86400000);
////////////////////////////////////////
var d = new Date("2015-03-25");
var d = new Date("2015-03");
var d = new Date("2015");
var d = new Date("2015-03-25T12:00:00Z");
var d = new Date("2015-03-25T12:00:00-06:30");
var d = new Date("03/25/2015");
var d = new Date("2015-3-25");
var d = new Date("2015/03/25");
var d = new Date("25-03-2015");
var d = new Date("Mar 25 2015");
var d = new Date("25 Mar 2015");
var d = new Date("January 25 2015");
var d = new Date("Jan 25 2015");
var d = new Date("JANUARY, 25, 2015");
/////////////////////////////////////////
var d = new Date(Date.parse("March 21, 2012"));
//0-January,1-February,2-March,3-April,4-May,5-June,
//6-July,7-August,8-September,9-October",10-November,11-December
alert((d.getMonth()+1)+" "+d.getDate()+", "+d.getFullYear());
////////////////////////////////////////
//getTime
var d = new Date();
alert(d.getTime());
//getFullYear
var d = new Date();
alert(d.getFullYear());
//getMonth
var d = new Date();
alert(d.getMonth());
//getMonth Array
var d = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
//0-January,1-February,2-March,3-April,4-May,5-June,
//6-July,7-August,8-September,9-October",10-November,11-December
alert(months[d.getMonth()]);
//getDate
var d = new Date();
alert(d.getDate());
//getHours
var d = new Date();
alert(d.getHours());
//getMinutes
var d = new Date();
alert(d.getMinutes());
//
var d = new Date();
alert(d.getSeconds());
var d = new Date();
alert(d.getMilliseconds());
var d = new Date();
alert(d.getDay());
var d = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
//0-Sunday,1-Monday,2-Tuesday,3-Wednesday,
//4-Thursday,5-Friday,6-Saturday
alert(days[d.getDay()]);
///////////////////////////////////////////////////
//setFullYear
var d = new Date();
d.setFullYear(2020);
alert(d.getFullYear());
//setFullYear
var d = new Date();
d.setFullYear(2020, 11, 3);
alert(d.getFullYear()+","+(d.getMonth()+1)+","+d.getDay());
//setMonth
var d = new Date();
d.setMonth(11);
alert(d.getMonth());
//setDate
var d = new Date();
d.setDate(15);
alert(d.getDate());
//setDate
var d = new Date();
d.setDate(d.getDate() + 50);
alert(d.getDate());
//setHours
var d = new Date();
d.setHours(22);
alert(d.getHours());
//setMinutes
var d = new Date();
d.setMinutes(30);
alert(d.getMinutes());
//setSeconds
var d = new Date();
d.setSeconds(30);
alert(d.getSeconds());
//setFullYear with if-else
var today, someday, text;
today = new Date();
someday = new Date();
someday.setFullYear(2020, 03, 12);
if (someday > today) {
text = "Today is before March 12, 2020.";
} else {
text = "Today is after March 12, 2020.";
}
alert(text);
///////////////////////////////////////////
var start = Date.now();
var millis;
var i = 0;
do {
i = i + 1;
millis = Date.now() - start
} while (millis < 1000);
alert(i);
//////////////////////////////////////////
var start = Date.now();
var millis = 0;
var i=0;
while (millis < 1000) {
i=i+1;
millis =Date.now() - start
}
alert(i)