Calendar.HOUR和Calendar.HOUR_OF_DAY有什么区别?什么时候使用Calendar.HOUR和Calendar.HOUR_OF_DAY?我有时感到困惑,有时Calendar.HOUR这个运行良好,而另一些时间Calendar.HOUR_OF_DAY这个运行良好。它们以int的形式返回什么?我已经阅读了this文档,但不理解其中的区别。有什么建议谢谢。
发布于 2016-05-15 17:09:10
来自http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#HOUR
Calendar.HOUR = get和set的字段编号,表示上午或下午的小时。小时用于12小时制的时钟。例如,在晚上10:04:15.250,时间是10点。
Calendar.HOUR_OF_DAY = get和set的字段编号,指示一天中的小时。HOUR_OF_DAY用于24小时制。例如,在晚上10:04:15.250,HOUR_OF_DAY是22。
发布于 2020-06-20 22:40:57
此代码将帮助您更好地理解
import java.util.Calendar; import java.util.GregorianCalendar;
public class test{ public static void main(String[] args) {
GregorianCalendar gc = new GregorianCalendar(2013, 8, 15, 21, 69,55); //分钟= 69等于1小时09分钟。此小时将添加到小时位置(21+1 = 22)//Sun Sep 15 22:09:55 IST 2013
p(gc, Calendar.YEAR); //gives year
p(gc, Calendar.MONTH); // gives month staring at 0 for January
p(gc, Calendar.DATE); // date
p(gc, Calendar.DAY_OF_WEEK);// Sunday=1, Monday=2, .....Saturday -7
p(gc, Calendar.WEEK_OF_MONTH);//what week its running in week ,whether its first or second;
p(gc, Calendar.DAY_OF_WEEK_IN_MONTH);//In this case, How may times does Sunday is repeating in the month = 3;
p(gc, Calendar.DAY_OF_YEAR);//count of the day in the year
p(gc, Calendar.HOUR);//12 hour format. if the time is 22:09:55, answer would be (22-12)=10
p(gc, Calendar.HOUR_OF_DAY);// hour of day that is 22 (24h format)
p(gc, Calendar.MINUTE);// 09
p(gc, Calendar.SECOND);// 55
System.out.println();
System.out.println(gc.getTime());}
static void p(Calendar c, int type) {
System.out.print(c.get(type) + "-");}}
*输出:
2013-8-15-1-3-3-258-10-22-9-55
Sun Sep 15 22:09:55 IST 2013
*
https://stackoverflow.com/questions/37236381
复制相似问题