java中设置准确的时间日期类的用法
5.日期Date相关类:
题目1: 设置准确的时间(jdk1.1以后Date的setHours不被推荐了,所以要用Calendar设置时间)
import java.util.*;
public class Test {
public static void main(String[] args) {
Date date;
Calendar cal=Calendar.getInstance();
cal.set(Calendar.YEAR,2008);
cal.set(Calendar.MONTH,1);
cal.set(Calendar.DAY_OF_MONTH,23);
cal.set(Calendar.HOUR_OF_DAY,16);//不要用Calendar.HOUR,马克-to-win,它是相对于上午和下午的
cal.set(Calendar.MINUTE, 3);
cal.set(Calendar.SECOND, 3);
date=cal.getTime();
System.out.println("date is"+date);
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/101752980