getDate()
Returns the current date according to the computer's local time. It returns a object with year, month, day.
Syntax
getDate(); /* returns { y : current year ,
m : current month ,
day : current day }
Example
setCanvas(elem);
function draw(){
t=getDate();
switch(t.day){
case 1:
case 21:
case 31:
dn="st"
break;
case 2:
case 22:
dn="nd"
break;
case 3:
case 23:
dn="rd"
break;
default:
dn="th"
break;
}
switch(t.m){
case 1:
mn="st"
break;
case 2:
mn="nd"
break;
case 3:
mn="rd"
break;
default:
mn="th"
break;
}
new text(100,HEIGHT/2-60,"Today is "+t.day+dn+" day",60,'Montserrat',500,'#fff',0,'#69f506','start');
new text(100,HEIGHT/2,"of "+t.m+mn+" month",60,'Montserrat',500,'#fff',0,'#69f506','start');
new text(100,HEIGHT/2+60,"of the Year "+t.y,60,'Montserrat',500,'#fff',0,'#69f506','start');
}
draw()
getDateString(format);
Returns the current date according to the computer's local time. It returns a string with the date according to the format.
Syntax
getDateString('mm/dd/yyyy'); //returns in the form "01/30/2022"
Parameters
format | String : format in which the date is to be returned Possible formats are :
|
Example
function draw(){
formats=[
'mm/dd/yyyy',
'dd/mm/yyyy',
'yyyy/mm/dd',
'yyyy/dd/mm',
'dd/yyyy/mm',
'mm/yyyy/dd'
]
formats2=[
'mm-dd-yyyy',
'dd-mm-yyyy',
'yyyy-mm-dd',
'yyyy-dd-mm',
'dd-yyyy-mm',
'mm-yyyy-dd'
]
for(i=0;i<formats.length;i++){
t=getDateString(formats[i]);
t2=getDateString(formats2[i]);
new text(50,60+i*HEIGHT/8,"Today is "+t,30,'Montserrat',500,'#fff',0,`hsl(${i*50},100%,50%)`,'start');
new text(450,60+i*HEIGHT/8,"Today is "+t2,30,'Montserrat',500,'#fff',0,`hsl(${i*50},100%,50%)`,'start');
}
}
draw();