https://www.myziyuan.com/
- qian
- 日期:年:today.getFullYear();月:today.getMonth() + 1;日:today.getDate();中间分隔符及小于10补0的方法参照你上面的代码搞一下
- 2021-03-23 13:50:01
- dafvzzz9
- 编得我有点小累,连分都没有,不过算了,因为要参加比赛,当练习了~import java.util.*;public class calendar { public static void main(String[] args) { new calendar().makeCalendar(); } public void makeCalendar() { int i; int j; int year = 0; int month = 0; int week = 0; int totalDay = 0; Scanner scanner = new Scanner(System.in); Calendar ca = Calendar.getInstance(); printAsterisk(); System.out.print("欢 迎 使 用 万 年 历"); printAsterisk(); System.out.print("\n\n请输入年份:"); year = scanner.nextInt(); System.out.print("\n\n请输入月份:"); month = scanner.nextInt() ; ca.set(year, month - 1,1); week = ca.get(Calendar.DAY_OF_WEEK)-1;//获取输入月第一天是星期几 if( month != 2) totalDay = calculatetotalDay(year , month); else { if(judgeLeap_year(year)) totalDay = calculatetotalDay(year , month) + 1;//如果是闰年,加一天 else totalDay = calculatetotalDay(year , month); } System.out.println("\n\n\n星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六"); for(i = 0;i < week;i++) { System.out.print("\t"); } for( i = 1; i < (8 - week);i++) System.out.print(i + "\t"); for( i = (8 - week),j = 0;i <= totalDay;i++,j++) { if(j % 7 == 0) System.out.println(); System.out.print(i+"\t"); } } public void printAsterisk() { int i; for( i = 0 ; i < 18;i++) System.out.print("*"); } //获取输入月的天数 public int calculatetotalDay(int year ,int month) { int result = 0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: result = 31; break; case 4: case 6: case 9: case 11:result = 30; break; default:result = 28; break; } return result; } //判断闰年 public boolean judgeLeap_year(int year) { if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return true; else return false; }}
- 2021-02-12 11:36:05
- 至深科技
- 网页设计 求一简单的日历代码,简单精练...放在你<body></body>之间就OK了...<script type="text/javascript"> var date=new Date(); var weekArray=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); var today="今天是"+date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日 "+weekArray[date.getDay()]; document.write(today);</script>
- 2021-02-12 11:36:05