• 关于日期的java小程序,写的比较粗糙


     1 //2013-10-7
     2 import java.util.*;
     3 import java.text.DateFormatSymbols;
     4 public class dateprint{
     5     public static void main(String[] args){
     6         int year,month,day;
     7         String input;
     8         Scanner in=new Scanner(System.in);
     9         input=in.nextLine();
    10         year=Integer.parseInt(input.substring(0,4));
    11         month=Integer.parseInt(input.substring(5,7));
    12         day=Integer.parseInt(input.substring(8));
    13         PRINT a=new PRINT();
    14         a.Monthprint(year,month,day);
    15             
    16     }
    17 }
    18 
    19 class PRINT{
    20     public void Monthprint(int y,int m,int D){
    21         GregorianCalendar d=new GregorianCalendar(y,m,D);
    22 
    23         int today=d.get(Calendar.DAY_OF_MONTH);
    24         int month=d.get(Calendar.MONTH);
    25 
    26         d.set(Calendar.DAY_OF_MONTH,1);        //将d设为该月的第一天
    27 
    28         int weekday=d.get(Calendar.DAY_OF_WEEK);   //得到d是星期几
    29         int firstdayofweek=d.getFirstDayOfWeek();
    30 
    31         int indent=0;                //判断第一周前面有几个空
    32         while(weekday!=firstdayofweek){
    33             indent++;
    34             d.add(Calendar.DAY_OF_WEEK,-1);
    35             weekday=d.get(Calendar.DAY_OF_WEEK);
    36         }
    37 
    38         //打印weekday names
    39         String[] weekdayname=new DateFormatSymbols().getShortWeekdays();
    40         do{
    41             System.out.printf("%4s",weekdayname[weekday]);
    42             d.add(Calendar.DAY_OF_MONTH,1);
    43             weekday=d.get(Calendar.DAY_OF_WEEK);
    44         }while(weekday!=firstdayofweek);
    45 
    46         System.out.println();
    47 
    48         for(int i=1;i<=indent;i++)
    49           System.out.print("    ");
    50         d.set(Calendar.DAY_OF_MONTH,1);
    51 
    52         do{
    53             int day=d.get(Calendar.DAY_OF_MONTH);
    54             System.out.printf("%3d",day);
    55 
    56             if(day==today) System.out.print("*");
    57             else System.out.print(" ");
    58 
    59             d.add(Calendar.DAY_OF_MONTH,1);
    60             weekday=d.get(Calendar.DAY_OF_WEEK);
    61 
    62             if(weekday==firstdayofweek) System.out.println();
    63         }while(d.get(Calendar.MONTH)==month);
    64 
    65         if(weekday!=firstdayofweek) System.out.println();
    66         
    67     }
    68 }
  • 相关阅读:
    WCF、WebAPI、WCFREST、WebService之间的区别
    常见的排序方法
    PHP中日期时间函数date()用法总结
    controller中获取全局配置111
    Zf2 自定义组件库如何设置
    module/config/module.config.php文件内涵定义
    zf2环境设置
    菜菜鸟Zend Framework 2 不完全学习涂鸦(四)-- 模块
    菜菜鸟Zend Framework 2 不完全学习涂鸦(三)-- 例子功能设置
    菜菜鸟Zend Framework 2 不完全学习涂鸦(二)-- 类库共享
  • 原文地址:https://www.cnblogs.com/wxhzt/p/3355790.html
Copyright © 2020-2023  润新知