📄 mycalendar.java
字号:
leapMonth=make_mday(i);
for (m=1;m<=nmth &&offset>0;m++) offset-=mday[m];
if (offset<0) offset+=mday[--m];
d.l= 0;
if (leapMonth>0){
yesNo=(leapMonth==(m-1));
if (yesNo) d.l=1;
else
d.l=0;
if (m>leapMonth) --m;
}
d.m=m;
d.d= (int) (offset+1);
}
public int CmpDate(int month1,int day1,int month2,int day2){
if (month1!=month2) return(month1-month2);
if (day1!=day2) return(day1-day2);
return(0);
}
public void solar2Lunar(){
double offset;
offset=solar2Day(solar);
solar.w=(int)(offset+solarFirstDate.w)%7;
if(solar.h==23) offset++;
day2Lunar(offset,lunar);
lunar.h=solar.h;
}
public double Solar2Day(MyDate d){
return (Solar2Day1(d)-Solar2Day1(solarFirstDate));
}
public double Solar2Day1(MyDate d){
int delta,i;
double offset;
delta=d.y-byr;
offset=delta*365+Math.floor(delta/4)-Math.floor(delta/100)+Math.floor(delta/400);
for (i=1;i<d.m;i++);
offset+=daysInSolarMonth[i];
if ((d.m > 2) && LeapYear(d.y)) offset++;
offset+=d.d-1;
return offset;
}
/*public String Lunar(int y,int m,int d){
solar.y=y;
solar.m=m;
solar.d=d;
solar2Lunar();
String answer;
if (lunar.d==1) answer=""+(lunar.l==1?"闰":"")+monthGB[lunar.m-1]+"月";
else answer=dayGB[lunar.d-1];
return answer;
}*/
/*
//根据给定的年月及当月的公历天数得到每个日期的农历日子名
public void CalMth(int y,int m,int nd){
solar.y=y;
solar.m=m;
solar.d=1;
solar2Lunar();
String result[]= new String [50];
for (int i=0;i<50;i++)
result[i]="";
// result[1]=dayGB[lunar.d];
int j=0;
for (int i=0;i<nd;i++){
if ((lunar.d+i)>=30) {
solar.y=y;
solar.m=m;
solar.d=i+1;
solar2Lunar();
result[i+1]=cday(lunar.d);
j=i;
}
else {
result[i+1]=cday(lunar.d+i-j);
}
}
}*/
//返回农历年
public String getNlYear(){
String[] allYearGB = {"甲子[鼠]","乙丑[牛]","丙寅[虎]","丁卯[兔]","戊辰[龙]","己巳[蛇]","庚午[马]","辛未[羊]","壬申[猴]","癸酉[鸡]",
"甲戌[狗]","乙亥[猪]","丙子[鼠]","丁丑[牛]","戊寅[虎]","己卯[兔]","庚辰[龙]","辛巳[蛇]","壬午[马]","癸未[羊]",
"甲申[猴]","乙酉[鸡]","丙戌[狗]","丁亥[猪]","戊子[鼠]","己丑[牛]","庚寅[虎]","辛卯[兔]","壬辰[龙]","癸巳[蛇]",
"甲午[马]","乙未[羊]","丙申[猴]","丁酉[鸡]","戊戌[狗]","己亥[猪]","庚子[鼠]","辛丑[牛]","壬寅[虎]","癸卯[兔]",
"甲辰[龙]","乙巳[蛇]","丙午[马]","丁未[羊]","戊申[猴]","己酉[鸡]","庚戌[狗]","辛亥[猪]","壬子[鼠]","癸丑[牛]",
"甲寅[虎]","乙卯[兔]","丙辰[龙]","丁巳[蛇]","戊午[马]","己未[羊]","庚申[猴]","辛酉[鸡]","壬戌[狗]","癸亥[猪]" };
int numYear;
numYear = ((m_glYear - 4) % 60);
m_nlYear = allYearGB[numYear];
return m_nlYear;
}
//返回农历月
public String getNlMonth(){
if ((m_glYear<1900)||(m_glYear>=2050))
return "无法得到1900年-2050年之外的阴历月份";
m_glMonth = m_glMonth ;
solar.y=m_glYear;
solar.m=m_glMonth +1;
solar.d=1;
solar2Lunar();
int nd =0;
// result[1]=dayGB[lunar.d];
switch (m_glMonth) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
nd = 31;
break;
case 4: case 6: case 9: case 11:
nd =30;
break;
case 2:
if (((m_glYear%4)==0) && ((m_glYear%100)!=0) || ((m_glYear%400)==0))
nd = 29;
else
nd = 28;
}
int j=0;
// int i=m_glDay;
int i = m_glDay - 1;
if ((lunar.d+i)>=30) {
solar.y= m_glYear;
solar.m= m_glMonth +1;
solar.d=i+1;
solar2Lunar();
m_nlMonth =cmonth(lunar.d);
j=i;
}
else {
m_nlMonth =cmonth(lunar.d+i-j);
}
return m_nlMonth;
}
//返回农历日
public String getNlDay(){
m_glMonth = m_glMonth ;
solar.y=m_glYear;
solar.m=m_glMonth +1;
solar.d=1;
solar2Lunar();
int nd =0;
if ((m_glYear<1900)||(m_glYear>=2050))
return "无法得到1900年-2050年之外的阴历日期";
// result[1]=dayGB[lunar.d];
switch (m_glMonth) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
nd = 31;
break;
case 4: case 6: case 9: case 11:
nd =30;
break;
case 2:
if (((m_glYear%4)==0) && ((m_glYear%100)!=0) || ((m_glYear%400)==0))
nd = 29;
else
nd = 28;
}
int j=0;
// int i=m_glDay;
int i = m_glDay - 1;
if ((lunar.d+i)>=30) {
solar.y= m_glYear;
solar.m= m_glMonth +1;
solar.d=i+1;
solar2Lunar();
m_nlDay =cday(lunar.d);
j=i;
}
else {
m_nlDay =cday(lunar.d+i-j);
}
return m_nlDay;
}
//计算节气
/* public String getTerm()
{
int baseDays = 365;
int baseHours = 5;
int baseMinutes = 48;
int baseSecond = 46;
int times ;
times = m_glYear - 1900;
Calendar dateBase = Calendar.getInstance();
dateBase.set(m_glYear,m_glMonth,m_glDay - baseDays * times,m_glHours +3 - baseHours * times ,
0 - baseMinutes *times,0 - baseSecond *times);
int month,day;
String result= new String ();
month = dateBase.get (dateBase.MONTH );
day = dateBase.get(dateBase.DATE );
switch (month) {
case 0:
if (day == 6)
result ="小寒";
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
;
}
return result;
}*/
//显示日历
public String makeCalendar(int year,int month,int days){
String content = new String ();
int iDays=0;
int firstDay;
Calendar cDate=Calendar.getInstance();
cDate.set (year,month-1,1);
content="";
firstDay = cDate.get(cDate.DAY_OF_WEEK) ;
switch (m_glMonth) {
case 0: case 2: case 4: case 6: case 7: case 9: case 11:
iDays = 31;
break;
case 3: case 5: case 8: case 10:
iDays =30;
break;
case 1:
if (((m_glYear%4)==0) && ((m_glYear%100)!=0) || ((m_glYear%400)==0))
iDays = 29;
else
iDays = 28;
}
// cDate.set (year,month,iDays);
int countDays=1;
String httpFirst="<td height=\"18\" width=\"23\">";
String httpSecond = "</td>";
String httpLink="<a href=\"DateShowDay?";
String httpLink2 =">";
String httpLinkEnd="</a>";
for (int i=0;i<6;i++)
{content += "<tr align=\"middle\">";
for (int j=0;j< 7;j++)
{
if (((i==0) && (j < firstDay - 1)) || countDays > iDays)
{ content += httpFirst;
content += httpSecond;}
else
{
if ((countDays == days) || (days == 0))
{
content += httpFirst;
content += httpLink;
content += "y=";
content += year;
content += "&m=";
content += month ;
content += "&d=";
content += countDays;
content += "\"";
content += httpLink2;
if ((countDays==days)||(countDays==m_glDay))
content +="<font color=\"#C000FF\"><b>";
else
content +="<font color=\"#0000FF\"><b>";
content += countDays ;
content +="</b></font>";
content += httpLinkEnd;
content += httpSecond ;
countDays ++;
}
else
{
content += httpFirst;
content += countDays ;
content += httpSecond ;
countDays ++;
}
}
}
content +="</tr>";
}
return content;
}
public int getMaxDay(int nYear,int nMonth){
switch (nMonth) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
m_maxDay = 31;
break;
case 4: case 6: case 9: case 11:
m_maxDay =30;
break;
case 2:
if (((nYear%4)==0) && ((nYear%100)!=0) || ((nYear%400)==0))
m_maxDay = 29;
else
m_maxDay = 28;
}
return m_maxDay;
}
public String getWeek(){
Calendar mDate= Calendar.getInstance ();
mDate.set(m_glYear,m_glMonth,m_glDay);
int nWeek=0;
nWeek = mDate.get(mDate.DAY_OF_WEEK );
String sWeek = new String ();
switch (nWeek) {
case 1:
sWeek ="星期日";
break;
case 2:
sWeek ="星期一";
break;
case 3:
sWeek ="星期二";
break;
case 4:
sWeek ="星期三";
break;
case 5:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -