本文整理汇总了Java中java.util.GregorianCalendar.JANUARY属性的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.JANUARY属性的具体用法?Java GregorianCalendar.JANUARY怎么用?Java GregorianCalendar.JANUARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.JANUARY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dateToJulian
public static long dateToJulian(Date date) {
GregorianCalendar calendarDate = new GregorianCalendar();
calendarDate.setTime(date);
Calendar calendarBegin = new GregorianCalendar(1, GregorianCalendar.JANUARY, 1);
long millisecondsDate = calendarDate.getTimeInMillis();
long millisecondsBegin = calendarBegin.getTimeInMillis();
long diff = millisecondsDate - millisecondsBegin;
long diffDays = diff / (24 * 60 * 60 * 1000) - 1;
return diffDays;
}
示例2: julianToDate
public static Date julianToDate(long date) {
GregorianCalendar calendarBegin = new GregorianCalendar(1, GregorianCalendar.JANUARY, 1);
long millisecondsBegin = calendarBegin.getTimeInMillis();
long diff = date * (24 * 60 * 60 * 1000);
long millisecondsDate = diff + millisecondsBegin;
int days = (int) (millisecondsDate / (24 * 60 * 60 * 1000));
GregorianCalendar calendarDate = new GregorianCalendar();
calendarDate.setTimeInMillis(0);
calendarDate.add(GregorianCalendar.DAY_OF_MONTH, days + 1);//todo : why +1 ?
return calendarDate.getTime();
}