/* 来自 nowjava - 时 代 Java*/
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
//get current date, year and month
System.out.println("Current Year is : " + now.get(Calendar.YEAR));
//month start from 0 to 11
System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1 ));
System.out.println("Current Date is : " + now.get(Calendar.DATE));
//get current time information
System.out.println("Current Hour in 12 hour format is : "
+ now.get(Calendar.HOUR));
/*
n o w j a v a . c o m 提供
*/
System.out.println("Current Hour in 24 hour format is : "
+ now.get(Calendar.HOUR_OF_DAY));
System.out.println("Current Minute is : " + now.get(Calendar.MINUTE));
System.out.println("Current Second is : " + now.get(Calendar.SECOND));
System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND));
//display full date time
System.out.println("Current full date time is : " +
(now.get(Calendar.MONTH) + 1)
+ "-"
+ now.get(Calendar.DATE)
+ "-"
+ now.get(Calendar.YEAR)
+ " "
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。