+ 5
How to make a First and last day of the Year ?
var fullDate=new Date(); var Days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; var y=fullDate.getFullYear(); var m=fullDate.getMonth(); var first_day=new Date(y,m,1).getDay(); var TotDays=fullDate.getDate(); var StartDay=Days[first_day]; document.write("Start Day:"+StartDay+"<br>"); NumberOfDays=new Date(y,m+1,0).getDate(); var last=new Date(y,m,NumberOfDays).getDay(); document.write("End Day:"+Days[last]+"<br>");
3 Respostas
+ 5
JavaScript Get Date Methods
https://www.w3schools.com/js/js_date_methods.asp
+ 5
var date = new Date();
var first=new Date(date.getFullYear(), 0, 1).toLocaleString("default", { weekday: "long" });
var last=new Date(date.getFullYear(), 11, 31).toLocaleString("default", { weekday: "long" });
+ 1
#include <iostream>
using namespace std;
int leapcheck(int yr){
if(yr%400==0)
return 1;
else if(yr%100==0)
return 0;
else if(yr%4==0)
return 1;
else
return 0;
}
int main() {
int diff,year,nlp,d,val,d0=1,lp=0;
cin >> year;
diff=year-1; // taking year 1 as base case
for(int i=1;i<year;i++)
if(leapcheck(i)==1)
lp++;
nlp=diff-lp;
d=1+1*(nlp)+2*(lp); // d=d0+1*nlp+2*lp;
val=d%7;
switch(val){
case 1 :
cout << "1st day of the year " << year << " was Monday" << endl;
break;
case 2 :
cout << "1st day of the year " << year << " was Tuesday" << endl;
break;
case 3 :
cout << "1st day of the year " << year << " was Wednesday" << endl;
break;
case 4 :
cout << "1st day of the year " << year << " was Thursday" << endl;
break;
case 5 :
cout << "1st day of the year " << year << " was Friday" << endl;