List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:Main.java
/** * Get the displayable date from week and year * @param week week of year/*from w ww . j av a 2 s .c o m*/ * @param year year * @return Date string for displaying */ public static String getDate(int week, int year) { SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy"); Calendar cal = Calendar.getInstance(); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.YEAR, year); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.WEEK_OF_YEAR, week); // Log.i(TAG, sdf.format(cal.getTime())); cal.set(Calendar.DAY_OF_WEEK, 1); // Log.i(TAG, sdf.format(cal.getTime())); String start = sdf.format(cal.getTime()); cal.set(Calendar.DAY_OF_WEEK, 7); // Log.i(TAG, sdf.format(cal.getTime())); String end = sdf.format(cal.getTime()); return start + " to " + end; }
From source file:Main.java
/** * yyyyMMddHHmmss/*w ww . j av a2 s . c o m*/ */ public static String getFormatTime3(Calendar c) { DecimalFormat df = new DecimalFormat("00"); String strFileName = c.get(Calendar.YEAR) + df.format((c.get(Calendar.MONTH) + 1)) + df.format(c.get(Calendar.DAY_OF_MONTH)) + df.format(c.get(Calendar.HOUR_OF_DAY)) + df.format(c.get(Calendar.MINUTE)) + df.format(c.get(Calendar.SECOND)); return strFileName; }
From source file:Main.java
/** * Format calendar to string/*from w w w . j a v a2 s .co m*/ * @param c Calendar to convert * @param format String format of SimpleDateFormat * @return String converted */ public static String formatDate(Calendar c, String format) { if (c == null) { c = Calendar.getInstance(); c.setTimeInMillis(0); c.set(Calendar.YEAR, 1990); } return formatDate(c.getTime(), format); }
From source file:Main.java
public static boolean isDatesInSameMonth(long lhs, long rhs) { Calendar lhsCalendar = getCalendarWithTime(lhs); int lhsMonth = lhsCalendar.get(Calendar.MONTH); int lhsYear = lhsCalendar.get(Calendar.YEAR); Calendar rhsCalendar = getCalendarWithTime(rhs); int rhsMonth = rhsCalendar.get(Calendar.MONTH); int rhsYear = rhsCalendar.get(Calendar.YEAR); return (lhsMonth == rhsMonth) && (lhsYear == rhsYear); }
From source file:Main.java
/** * @param days//www .j av a 2s. c o m * number of days after September 02, 1975 (what happened on this * day?) * @return */ public static Calendar getDayFromQuickLogEntry(int days) { Calendar logDay = GregorianCalendar.getInstance(); logDay.set(Calendar.DAY_OF_MONTH, 2); logDay.set(Calendar.MONTH, Calendar.SEPTEMBER); logDay.set(Calendar.YEAR, 1975); logDay.add(Calendar.DAY_OF_YEAR, days); return logDay; }
From source file:Main.java
public static boolean areSameDays(long time1, long time2) { Calendar calendar = calendarThreadLocal.get(); if (calendar == null) { calendar = Calendar.getInstance(); calendarThreadLocal.set(calendar); }// www. j av a 2s.c om calendar.setTimeInMillis(time1 * 1000L); int y1 = calendar.get(Calendar.YEAR); int m1 = calendar.get(Calendar.MONTH); int d1 = calendar.get(Calendar.DATE); calendar.setTimeInMillis(time2 * 1000L); int y2 = calendar.get(Calendar.YEAR); int m2 = calendar.get(Calendar.MONTH); int d2 = calendar.get(Calendar.DATE); return y1 == y2 && m1 == m2 && d1 == d2; // return (time1 / (60 * 60 * 24)) == (time2 / (60 * 60 * 24)); }
From source file:Main.java
/** * Calculates the difference in days, rounding the operands down to the nearest day. * Ex. Jan 3rd 12:31 pm - Jan 2nd 4:00 pm * = Jan 3rd - Jan 2nd/*w w w . java 2 s . c o m*/ * = 1 day * @return The difference in days. */ public static int differenceInDays(GregorianCalendar minuend, GregorianCalendar subtrahend) { GregorianCalendar minuendFloor = new GregorianCalendar(minuend.get(Calendar.YEAR), minuend.get(Calendar.MONTH), minuend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar subtrahendFloor = new GregorianCalendar(subtrahend.get(Calendar.YEAR), subtrahend.get(Calendar.MONTH), subtrahend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar result = new GregorianCalendar(); result.setTimeInMillis(minuendFloor.getTimeInMillis() - subtrahendFloor.getTimeInMillis()); return result.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
/** * Liefert das Jahr in welchem das Semester begann. Dies ist besonders im Wintersemester nach dem Jahreswechsel wichtig * * @return Jahr in welchem das aktuelle Semester begann *//*w w w. j a v a 2 s. c o m*/ public static int getStartYearOfSemester() { final Calendar calendar = GregorianCalendar.getInstance(); if (calendar.get(Calendar.MONTH) <= Calendar.FEBRUARY) return calendar.get(Calendar.YEAR) - 1; return calendar.get(Calendar.YEAR); }
From source file:Main.java
public static boolean sameDay(Date then, Date now) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(then);/*from w ww.ja v a2 s. com*/ cal2.setTime(now); return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
/** * yyyy-MM-dd HH:mm:ss/*from www.j av a 2s . c om*/ */ public static String getFormatTime1(Calendar c) { if (null == c) { return "null"; } DecimalFormat df = new DecimalFormat("00"); String strCurrTime = c.get(Calendar.YEAR) + "-" + df.format((c.get(Calendar.MONTH) + 1)) + "-" + df.format(c.get(Calendar.DAY_OF_MONTH)) + " " + df.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + df.format(c.get(Calendar.MINUTE)) + ":" + df.format(c.get(Calendar.SECOND)); return strCurrTime; }