zoukankan      html  css  js  c++  java
  • CalculateWeekDay

    import java.util.*;
    import java.text.*;
    public class CalculateWeekDay {
    public static void main(String[] args) {
    Date date=new Date();
    SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(f.format(date));
    String str=f.format(date);
    String str1[]=str.split("-");
    int year=Integer.parseInt(str1 [0]);
    int month =Integer.parseInt(str1 [1]);
    int day =Integer.parseInt(str1 [2]);
    int total,week,i;
    boolean leap=false;
    leap=(year%400==0)|(year%100!=0)&(year%4==0);
    week=1;
    total=year-1980+(year-1980+3)/4;
    for(i=1;i<=month-1;i++){
    switch(i){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    total=total+31;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    total=total+30;
    break;
    case 2:
    if(leap)
    total=total+29;
    else
    total=total+28;
    break;
    }
    }
    total=total+day;
    week=(week+total)%7;
    System.out.print("today"+year+"-"+month+"-"+day+"is");
    switch(week){
    case 0:
    System.out.println("Sunday");
    break;
    case 1:
    System.out.println("Monday");
    break;
    case 2:
    System.out.println("Tuesday");
    break;
    case 3:
    System.out.println("Wednesday");
    break;
    case 4:
    System.out.println("Thursday");
    break;
    case 5:
    System.out.println("Friday");
    break;
    case 6:
    System.out.println("Saturday");
    break;
    }
    }

    }

  • 相关阅读:
    c#文件读取
    asp.net页面缓存学习
    JQuery学习
    如何在asp.net后台调用前台代码
    c#文件操作二
    oracler主键自动增长
    C#委托学习
    小技巧:DIV中显示字符不完整的解决方法
    英文名字的误区及起名方法
    SharePoint 2010 中提供的母版页
  • 原文地址:https://www.cnblogs.com/wlp1115/p/6557309.html
Copyright © 2011-2022 走看看