JAVAJDK -Calendar 遇到的 一个坑
Posted 飞鱼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVAJDK -Calendar 遇到的 一个坑相关的知识,希望对你有一定的参考价值。
Calendar是JDK 1.1增加的类
最近使用了下Calendar发现几个很让人抓狂的问题
源码:
public final static int SUNDAY = 1;
public final static int MONDAY = 2;
public final static int TUESDAY = 3;
public final static int WEDNESDAY = 4;
public final static int THURSDAY = 5;
public final static int FRIDAY = 6;
public final static int SATURDAY = 7;
你发现了么。是的这是真的,星期一(MONDAY) 对应的值为2,不是一,其他的值也是都向后措了1位数字。
同样的,源码:
public final static int JANUARY = 0;
public final static int FEBRUARY = 1;
public final static int MARCH = 2;
public final static int APRIL = 3;
public final static int MAY = 4;
public final static int JUNE = 5;
public final static int JULY = 6;
public final static int AUGUST = 7;
public final static int SEPTEMBER = 8;
public final static int OCTOBER = 9;
public final static int NOVEMBER = 10;
public final static int DECEMBER = 11;
没错,月份也有相同的问题。一不小心就会把时间处理错
以上是关于JAVAJDK -Calendar 遇到的 一个坑的主要内容,如果未能解决你的问题,请参考以下文章
安装allure时遇到的坑:JAVA_HOME is set to an invalid directory: D:Javajdk1.8.0_66 Please set the JAVA_HOM(代