List of utility methods to do Year From
Date | getYearStart(int year) get Year Start Calendar c = Calendar.getInstance(GMT_TIME_ZONE);
c.set(Calendar.YEAR, year);
c.set(Calendar.DAY_OF_YEAR, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
...
|
long | getYearStart(long ts) get Year Start Calendar calendar = Calendar.getInstance(gmt); calendar.setTimeInMillis(ts); int year = calendar.get(Calendar.YEAR); calendar.clear(); calendar.set(year, 0, 1); return calendar.getTimeInMillis(); |
String | getYearStartTime() get Year Start Time return new GregorianCalendar().get(Calendar.YEAR) + "-01-01 00:00:00"; |
boolean | isInYear(String dateStr, int year) is In Year boolean flag = false; String[][] yearedge = getYearDateStr(year); SimpleDateFormat frm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = frm.parse(dateStr); String startTime = yearedge[0][0]; String endTime = yearedge[0][1]; Date startDate = frm.parse(startTime); ... |
Date | setYears(Date date, int amount) Sets the years field to a date returning a new object. return set(date, Calendar.YEAR, amount);
|
String | toNowYear(Date date) to Now Year String strDate = ""; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); strDate = dateFormat.format(date); return strDate; |
String | toShortW3CDTF(Date d, boolean yearOnly) to Short WCDTF SimpleDateFormat format = new SimpleDateFormat(yearOnly ? "yyyy" : "yyyy-MM-dd"); return format.format(d); |
String | year() year return now("yyyy"); |
int | year(Date date) year String year = yearFormat.format(date);
return Integer.valueOf(year);
|
int | year(long time) year final Calendar FINDER = new GregorianCalendar(UTC_TIME_ZONE); FINDER.setTimeInMillis(time); return FINDER.get(Calendar.YEAR); |