关闭

GregorianCalendar(标准阳历) 示例

1332人阅读 评论(0) 收藏 举报

//Demonstrate GregorianCalendar.
import java.util.*;
class GregorianCalendarDemo{
 public static void main(String[] args)
 {
  String months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  int year;

  /*Create a Gregorian calendar initialized with the current date ant time in the
     default locale and timezone.
  */
  GregorianCalendar gCalendar = new GregorianCalendar();

  //Display current time and date information.
  System.out.print("Date: ");
  System.out.print(months[gCalendar.get(Calendar.MONTH)]);
  System.out.print(" " + gCalendar.get(Calendar.DATE) + " ");
  System.out.println(year = gCalendar.get(Calendar.YEAR));

  System.out.print("Time: ");
  System.out.print(gCalendar.get(Calendar.HOUR) + ":");
  System.out.print(gCalendar.get(Calendar.MINUTE) + ":");
  System.out.println(gCalendar.get(Calendar.SECOND));

  //Test if the current year is a leap year.
  if(gCalendar.isLeapYear(year)){
   System.out.println("The current year is a leap year ");
  }else{
   System.out.println("The current year is not a leap year ");
  }
 }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:681050次
    • 积分:7856
    • 等级:
    • 排名:第2629名
    • 原创:75篇
    • 转载:247篇
    • 译文:0篇
    • 评论:64条
    文章分类
    最新评论