• 获取某年某月某日是周几


    public static void getweek(){

    /*
    遇到整百年时(如2000,1900,300)要被400整除才是闰年,否则为平年
    (2000闰年,1900平年,300平年)
    ;遇到非整百年时(如2004,2005),只要被4整除就是闰年,不能被4整除为平年
    (2004闰年,2005平年)。
    闰年的2月有29天,平年的2月有28天。
    */
    Scanner scan = new Scanner(System.in);
    int allday = 0;//总天数
    System.out.println("请输入年份:");
    int year = scan.nextInt();//年
    System.out.println("请输入月份:");
    int month = scan.nextInt();//月
    System.out.println("请输入日期:");
    int day = scan.nextInt();//日
    if ((year % 100 != 0 && year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)) {
    System.out.println(year + " 是闰年!");
    }else {
    System.out.println(year + " 是平年!");
    }
    for (int i = 1900; i < year; i++) {
    if ((i % 100 != 0 && i % 4 == 0) || (i % 100 == 0 && i % 400 == 0)) {
    allday += 366;
    }else {
    allday += 365;
    }
    }
    for (int i = 1; i < month; i++) {
    switch (i) {
    case 4:
    case 6:
    case 9:
    case 11:
    allday += 30;
    break;
    case 2:
    if ((year % 100 != 0 && year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)) {
    allday += 29;
    }else {
    allday += 28;
    }
    break;
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    allday += 31;
    break;
    }
    }
    allday = allday + day;
    System.out.println(year + "年" + month + "月" + day + "日距 1900年1月1日 共 " + allday + " 天!");
    int week = allday % 7;
    System.out.println("周" + week);
    }

    /***********运行如下************/

    请输入年份:
    2016
    请输入月份:
    10
    请输入日期:
    3
    2016 是闰年!
    2016年10月3日距 1900年1月1日 共 42645 天!
    周1

  • 相关阅读:
    Android LogCat使用详解
    新时代新潮流WebOS 【20】WebKit的结构与解构
    Android调试的必杀技——反汇编
    真机缺少com.google.android.maps.jar解决方法:
    test
    VMware让ubuntu与win7共享文件方法
    android手机通过笔记本无线wifi上网
    新时代新潮流WebOS 【22】WebKit,鼠标引发的故事
    获取证书
    获取局域网内部机器的MAC地址
  • 原文地址:https://www.cnblogs.com/weloglog888/p/5929148.html
Copyright © 2020-2023  润新知