use of java.util.GregorianCalendar in project XobotOS by xamarin.
the class ZipEntry method setTime.
/**
* Sets the modification time of this {@code ZipEntry}.
*
* @param value
* the modification time as the number of milliseconds since Jan.
* 1, 1970.
*/
public void setTime(long value) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date(value));
int year = cal.get(Calendar.YEAR);
if (year < 1980) {
modDate = 0x21;
time = 0;
} else {
modDate = cal.get(Calendar.DATE);
modDate = (cal.get(Calendar.MONTH) + 1 << 5) | modDate;
modDate = ((cal.get(Calendar.YEAR) - 1980) << 9) | modDate;
time = cal.get(Calendar.SECOND) >> 1;
time = (cal.get(Calendar.MINUTE) << 5) | time;
time = (cal.get(Calendar.HOUR_OF_DAY) << 11) | time;
}
}
use of java.util.GregorianCalendar in project translationstudio8 by heartsome.
the class DateUtils method getdaysslice.
/**
* 返回两个日期间的天数,去除周末的天数
* @param startdate
* ,enddate 格式“yyyy-MM-dd”
* @return
*/
public static int getdaysslice(String startdate, String enddate) {
if (startdate == null || "".equals(startdate.trim()))
return 0;
if (enddate == null || "".equals(enddate.trim()))
return 0;
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date start = null;
java.util.Date end = null;
try {
start = myFormatter.parse(startdate);
end = myFormatter.parse(enddate);
} catch (Exception e) {
return 0;
}
long daynum = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000);
Calendar startcalendar = new GregorianCalendar();
startcalendar.setTime(start);
int n = 0;
for (int i = 0; i <= daynum; i++) {
if (startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || startcalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
startcalendar.add(Calendar.DAY_OF_MONTH, 1);
continue;
}
startcalendar.add(Calendar.DAY_OF_MONTH, 1);
n++;
}
return n;
}
use of java.util.GregorianCalendar in project translationstudio8 by heartsome.
the class DateUtils method isLeapYear.
/**
* 判断是否闰年
* @param ddate
* @return
*/
public static boolean isLeapYear(String ddate) {
/**
* 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年 3.能被4整除同时能被100整除则不是闰年
*/
Date d = strToDate(ddate);
GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
gc.setTime(d);
int year = gc.get(Calendar.YEAR);
if ((year % 400) == 0)
return true;
else if ((year % 4) == 0) {
if ((year % 100) == 0)
return false;
else
return true;
} else
return false;
}
use of java.util.GregorianCalendar in project hibernate-orm by hibernate.
the class Cat method calculateAge.
@PostLoad
public void calculateAge() {
Calendar birth = new GregorianCalendar();
birth.setTime(dateOfBirth);
Calendar now = new GregorianCalendar();
now.setTime(new Date());
int adjust = 0;
if (now.get(Calendar.DAY_OF_YEAR) - birth.get(Calendar.DAY_OF_YEAR) < 0) {
adjust = -1;
}
age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR) + adjust;
}
use of java.util.GregorianCalendar in project hibernate-orm by hibernate.
the class DateTypeDescriptor method unwrap.
@SuppressWarnings({ "unchecked" })
@Override
public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
if (value == null) {
return null;
}
if (java.sql.Date.class.isAssignableFrom(type)) {
final java.sql.Date rtn = java.sql.Date.class.isInstance(value) ? (java.sql.Date) value : new java.sql.Date(value.getTime());
return (X) rtn;
}
if (java.sql.Time.class.isAssignableFrom(type)) {
final java.sql.Time rtn = java.sql.Time.class.isInstance(value) ? (java.sql.Time) value : new java.sql.Time(value.getTime());
return (X) rtn;
}
if (java.sql.Timestamp.class.isAssignableFrom(type)) {
final java.sql.Timestamp rtn = java.sql.Timestamp.class.isInstance(value) ? (java.sql.Timestamp) value : new java.sql.Timestamp(value.getTime());
return (X) rtn;
}
if (Date.class.isAssignableFrom(type)) {
return (X) value;
}
if (Calendar.class.isAssignableFrom(type)) {
final GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(value.getTime());
return (X) cal;
}
if (Long.class.isAssignableFrom(type)) {
return (X) Long.valueOf(value.getTime());
}
throw unknownUnwrap(type);
}
Aggregations