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
public static boolean checkToday(String date) { Calendar today = Calendar.getInstance(); Calendar day = StringToCalendar(date); return ((today.get(Calendar.YEAR) == day.get(Calendar.YEAR)) && (today.get(Calendar.MONTH) == day.get(Calendar.MONTH)) && (today.get(Calendar.DAY_OF_MONTH) == day.get(Calendar.DAY_OF_MONTH))); }
From source file:Main.java
public static boolean isSameDay(long lhs, long rhs) { Calendar lhsCal = Calendar.getInstance(); Calendar rhsCal = Calendar.getInstance(); lhsCal.setTimeInMillis(lhs);/*from w w w . j a va 2s . co m*/ rhsCal.setTimeInMillis(rhs); return (lhsCal.get(Calendar.YEAR) == rhsCal.get(Calendar.YEAR)) && (lhsCal.get(Calendar.DAY_OF_YEAR) == rhsCal.get(Calendar.DAY_OF_YEAR)); }
From source file:Main.java
public static Date beginOfTheDay(@NonNull Date date) { Calendar inputDate = Calendar.getInstance(); inputDate.setTime(date);/*from ww w . j a v a 2 s.c o m*/ Calendar resultDate = Calendar.getInstance(); resultDate.set(inputDate.get(Calendar.YEAR), inputDate.get(Calendar.MONTH), inputDate.get(Calendar.DAY_OF_YEAR)); return resultDate.getTime(); }
From source file:Main.java
public static String getSeqWeek() { Calendar c = Calendar.getInstance(Locale.CHINA); String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR)); if (week.length() == 1) week = "0" + week; String year = Integer.toString(c.get(Calendar.YEAR)); return year + week; }
From source file:Main.java
public static Calendar getRandomDate(int baseYear) { synchronized (rand) { Calendar today = Calendar.getInstance(); int year = rand.nextInt(today.get(Calendar.YEAR) - baseYear + 1) + baseYear; int month = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.MONTH) - 1) + 1 : rand.nextInt(12) + 1;/*from w ww . j ava2 s . c om*/ int day = year == today.get(Calendar.YEAR) ? rand.nextInt(today.get(Calendar.DAY_OF_WEEK)) + 1 : rand.nextInt(29) + 1; return new GregorianCalendar(year, month, day); } }
From source file:Main.java
public static String getCurrentDateString() { Calendar currentCalendar = Calendar.getInstance(); currentYear = currentCalendar.get(Calendar.YEAR); return dateFormat.format(currentCalendar.getTimeInMillis()); }
From source file:Main.java
public static boolean isSameDay(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1);//www . j av a2s . co m cal2.setTime(date2); 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
public static String buildDateForUrl(Calendar calendar) { String day = (calendar.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "") + calendar.get(Calendar.DAY_OF_MONTH); String month = ((calendar.get(Calendar.MONTH) + 1) < 10 ? "0" : "") + (calendar.get(Calendar.MONTH) + 1); return calendar.get(Calendar.YEAR) + "" + month + "" + day; }
From source file:Main.java
public static boolean isBrithdayAvable(Long d) { if (d == null) { return false; }// w w w.ja v a 2 s .c o m boolean back = false; Calendar c = Calendar.getInstance(); c.setTimeInMillis(d.longValue()); Calendar current = Calendar.getInstance(); if (c.get(Calendar.YEAR) > 1801 && c.before(current) && c.get(Calendar.YEAR) <= current.get(Calendar.YEAR)) { return true; } return back; }
From source file:Main.java
public static String formatSimpleDateStr(int year, int monthOfYear, int dayOfMonth) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, monthOfYear); cal.set(Calendar.DATE, dayOfMonth); return SIMPLE_DATE_FORMAT.format(cal.getTime()); }