List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static String getSemesterString() { Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); if (getSemester() == 0) { year = year % 100;/*from w w w . j a v a2s. co m*/ int next_year = year + 1; return String.format(STRING_WINTER, year, next_year); } else { return String.format(STRING_SUMMER, year); } }
From source file:Main.java
public static int getSemester() { Calendar cal = Calendar.getInstance(); int month = cal.get(Calendar.MONTH); if (month > Calendar.FEBRUARY && month < Calendar.SEPTEMBER) return SUMMER_SEMESTER; else/*from w ww . j a v a2 s. c om*/ return WINTER_SEMESTER; }
From source file:Main.java
public static String getFormattedDate(long timeStampInMilliSeconds) { Calendar smsTime = Calendar.getInstance(); smsTime.setTimeInMillis(timeStampInMilliSeconds); Calendar now = Calendar.getInstance(); if (now.get(Calendar.DATE) == smsTime.get(Calendar.DATE)) { return "Today " + getTime(smsTime.getTimeInMillis()); } else if (now.get(Calendar.DATE) - smsTime.get(Calendar.DATE) == 1) { return "Yesterday " + getTime(smsTime.getTimeInMillis()); }/*from w ww .j a va2s . c o m*/ return dateParse(timeStampInMilliSeconds); }
From source file:Main.java
public static int gettimeinhours(long t) { Calendar c = new GregorianCalendar(); c.setTime(new Date(t)); return c.get(Calendar.HOUR_OF_DAY); }
From source file:Main.java
public static int getDayOfWeek() { Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == 1) { day = 7;//from w ww .j a v a2 s. c o m } else { day = day - 1; } return day; }
From source file:Main.java
public static boolean isDateInCurrentYear(long date) { Calendar currentCalendar = getCurrentCalendar(); int year = currentCalendar.get(Calendar.YEAR); Calendar targetCalendar = getCalendarWithTime(date); int targetYear = targetCalendar.get(Calendar.YEAR); return (year == targetYear); }
From source file:Main.java
public static Calendar setAsToday(Calendar aoCalendar) { Calendar loCalendar = Calendar.getInstance(); aoCalendar.set(Calendar.YEAR, loCalendar.get(Calendar.YEAR)); aoCalendar.set(Calendar.MONTH, loCalendar.get(Calendar.MONTH)); aoCalendar.set(Calendar.DAY_OF_MONTH, loCalendar.get(Calendar.DAY_OF_MONTH)); return aoCalendar; }
From source file:Main.java
private static int getYearOfBirth(Date dateOfBirth) { Calendar dob = Calendar.getInstance(); dob.setTime(dateOfBirth);/* w w w. j ava2 s . c o m*/ return dob.get(Calendar.YEAR); }
From source file:Main.java
public static int getAge(String year, String month, String day) throws NumberFormatException { int yearInt = Integer.parseInt(year); int monthInt = Integer.parseInt(month); int dayInt = Integer.parseInt(day); monthInt--;/*from w ww . ja va2s . co m*/ Calendar birthCal = Calendar.getInstance(); birthCal.set(yearInt, monthInt, dayInt); Calendar todayCal = Calendar.getInstance(); int diff = todayCal.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR); if (birthCal.get(Calendar.MONTH) > todayCal.get(Calendar.MONTH) || (birthCal.get(Calendar.MONTH) == todayCal.get(Calendar.MONTH) && birthCal.get(Calendar.DATE) > todayCal.get(Calendar.DATE))) { diff--; } return diff; }
From source file:Main.java
public static Calendar roundMinutesAndHour(Calendar time, int TIME_PICKER_INTERVAL) { int minute = time.get(Calendar.MINUTE); int hour = time.get(Calendar.HOUR_OF_DAY); if (time.get(Calendar.MINUTE) % TIME_PICKER_INTERVAL != 0) { int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL); minute = minuteFloor + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0); if (minute == 60) { hour++;//from w ww . j a va2 s .c o m minute = 0; } } time.set(Calendar.HOUR_OF_DAY, hour); time.set(Calendar.MINUTE, minute); return time; }