zoukankan      html  css  js  c++  java
  • java打印日历

    简单的demo

     1 package com.test.transport.service;
     2 
     3 import java.text.DateFormatSymbols;
     4 import java.util.Calendar;
     5 import java.util.Locale;
     6 
     7 public class DisplayCalendar {
     8     public static void main(String args[]) {
     9         Locale.setDefault(Locale.US);
    10         Calendar calendar = Calendar.getInstance();
    11         calendar.setLenient(true);
    12         int today = calendar.get(Calendar.DAY_OF_MONTH);//当天
    13         int month = calendar.get(Calendar.MONTH);//当月
    14         int firstDayOfWeek = calendar.getFirstDayOfWeek();//每周从周几开始
    15         calendar.set(Calendar.DAY_OF_MONTH, 1);
    16         int firstday = calendar.get(Calendar.DAY_OF_WEEK);
    17         String[] weekdayNames = new DateFormatSymbols().getShortWeekdays();
    18         for(int i=1;i<8;i++){
    19             System.out.printf("%4s", weekdayNames[i]);
    20         }
    21         System.out.println();
    22         do {
    23             int day = calendar.get(Calendar.DAY_OF_MONTH);
    24             if(day == 1){
    25                 System.out.print(" ");
    26                 for(int i =0;i<firstday-1;i++){
    27                     System.out.print("    ");
    28                 }
    29             }
    30             System.out.printf("%3d", day);
    31             if (day == today) {
    32                 System.out.print("*");
    33             } else {
    34                 System.out.print(" ");
    35             }
    36             calendar.add(Calendar.DAY_OF_MONTH, 1);
    37             if (calendar.get(Calendar.DAY_OF_WEEK) == firstDayOfWeek) {
    38                 System.out.println();
    39                 System.out.print(" ");
    40             }
    41         } while (calendar.get(Calendar.MONTH) == month);
    42     }
    43 }

    输出结果:

  • 相关阅读:
    关于模式窗体的缓存问题的解决方案
    C# 读取网页
    C# 压缩文件
    C#实现反射调用动态加载的DLL文件中的方法
    在线程中修改窗体控件内容
    C# 启用双缓存,避免ListView控件加载数据时闪烁
    JBuilder2005破解方法
    C# combbox datatable 赋值
    今天感觉到秋凉了~
    烦人的流程图~~~
  • 原文地址:https://www.cnblogs.com/ikuman/p/2803749.html
Copyright © 2011-2022 走看看