Java 程序可在具体日期添加指定的时间
下面是一个示例,向具体日期添加指定的时间。
程序
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Date d1 = new Date();
Calendar cl = Calendar. getInstance();
cl.setTime(d1);
System.out.println("today is " + d1.toString());
cl. add(Calendar.MONTH, 1);
System.out.println("date after a month will be " + cl.getTime().toString() );
cl. add(Calendar.HOUR, 70);
System.out.println("date after 7 hrs will be " + cl.getTime().toString() );
cl. add(Calendar.YEAR, 3);
System.out.println("date after 3 years will be " + cl.getTime().toString() );
}
}输出
today is Mon Jun 22 02:47:02 IST 2009 date after a month will be Wed Jul 22 02:47:02 IST 2009 date after 7 hrs will be Wed Jul 22 09:47:02 IST 2009 date after 3 years will be Sun Jul 22 09:47:02 IST 2012
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP