PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>月历表</title>
<?php
 $MONTH = array("元月","一月","二月","三月"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Java实现输入一个年份输出日历的代码: ```java import java.util.Scanner; public class Calendar { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入一个年份(1980-2050):"); int year = scanner.nextInt(); if (year < 1980 || year > 2050) { System.out.println("输入的年份不在1980-2050之间!"); return; } int weekDay = getWeekDay(year, 1, 1); // 获取该1月1日是星期几 int daysOfMonth; // 当前月份的天数 for (int month = 1; month <= 12; month++) { switch (month) { case 1: System.out.println("------------" + year + "1月------------"); daysOfMonth = 31; break; case 2: System.out.println("------------" + year + "2月------------"); if (isLeapYear(year)) { daysOfMonth = 29; } else { daysOfMonth = 28; } break; case 3: System.out.println("------------" + year + "3月------------"); daysOfMonth = 31; break; case 4: System.out.println("------------" + year + "4月------------"); daysOfMonth = 30; break; case 5: System.out.println("------------" + year + "5月------------"); daysOfMonth = 31; break; case 6: System.out.println("------------" + year + "6月------------"); daysOfMonth = 30; break; case 7: System.out.println("------------" + year + "7月------------"); daysOfMonth = 31; break; case 8: System.out.println("------------" + year + "8月------------"); daysOfMonth = 31; break; case 9: System.out.println("------------" + year + "9月------------"); daysOfMonth = 30; break; case 10: System.out.println("------------" + year + "10月-----------"); daysOfMonth = 31; break; case 11: System.out.println("------------" + year + "11月-----------"); daysOfMonth = 30; break; default: System.out.println("------------" + year + "12月-----------"); daysOfMonth = 31; } // 输出日历表头 System.out.println("日\t一\t二\t三\t四\t五\t六"); // 输出该月第一天之前的空格 for (int i = 0; i < weekDay; i++) { System.out.print("\t"); } // 输出该月的每一天 for (int day = 1; day <= daysOfMonth; day++) { System.out.print(day + "\t"); weekDay++; if (weekDay == 7) { // 周六之后换行 System.out.println(); weekDay = 0; } } System.out.println(); // 换行 } } // 判断是否闰 public static boolean isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; } // 获取某一天是星期几,0表示星期日,1表示星期一,依次类推 public static int getWeekDay(int year, int month, int day) { if (month == 1 || month == 2) { // 1月和2月看作上一的13月和14月 month += 12; year--; } int century = year / 100; year %= 100; int weekDay = year + year / 4 + century / 4 - 2 * century + 26 * (month + 1) / 10 + day - 1; weekDay %= 7; if (weekDay < 0) { weekDay += 7; } return weekDay; } } ``` 运行程序后,输入年份即可输出所有月份日历

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值