import java.util.Calendar;
/*
来 自*
时 代 J a v a 公 众 号
*/
public class Main {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1)
+ "-"
+ now.get(Calendar.DATE)
+ "-"
+ now.get(Calendar.YEAR));
System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY)
/**
* N o w J a v a . c o m - 时代Java 提 供
**/
+ ":"
+ now.get(Calendar.MINUTE)
+ ":"
+ now.get(Calendar.SECOND));
//add hours to current date using Calendar.add method
now.add(Calendar.HOUR,10);
System.out.println("New time after adding 10 hours : "
+ now.get(Calendar.HOUR_OF_DAY)
+ ":"
+ now.get(Calendar.MINUTE)
+ ":"
+ now.get(Calendar.SECOND));
System.out.println("New date after adding 10 hours : "
+ (now.get(Calendar.MONTH) + 1)
+ "-"
+ now.get(Calendar.DATE)
+ "-"
+ now.get(Calendar.YEAR));
//subtract hours from current date using Calendar.add method
now = Calendar.getInstance();
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。