List of usage examples for java.util Calendar get
public int get(int field)
From source file:Util.java
public static int getYearFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*ww w. j av a 2 s .c o m*/ return calendar.get(Calendar.YEAR); }
From source file:Main.java
/** * //from ww w . j a v a2 s . c o m * @return */ public static String ID_DayName() { Calendar cal = Calendar.getInstance(); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); String weekDayName = ""; if (Calendar.MONDAY == dayOfWeek) { weekDayName = "Senin"; } else if (Calendar.TUESDAY == dayOfWeek) { weekDayName = "Selasa"; } else if (Calendar.WEDNESDAY == dayOfWeek) { weekDayName = "Rabu"; } else if (Calendar.THURSDAY == dayOfWeek) { weekDayName = "Kamis"; } else if (Calendar.FRIDAY == dayOfWeek) { weekDayName = "Jumat"; } else if (Calendar.SATURDAY == dayOfWeek) { weekDayName = "Sabtu"; } else if (Calendar.SUNDAY == dayOfWeek) { weekDayName = "Minggu"; } return weekDayName; }
From source file:Main.java
public static int getDayOfMonth(int offset) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, offset); return calendar.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
public static String getHour(long time) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time);//from www. j a v a 2 s. c o m int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); String times = "" + hour; if (minute < 10) { times += ":0" + minute; } else { times += ":" + minute; } return times; }
From source file:Main.java
public static String getDateYYYYMM(int offset) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, offset); return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH); }
From source file:Main.java
public static int getWeek(int year, int month, int day) { Date date = new Date(year - 1900, month - 1, day); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w ww. j a va 2s .c o m int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); return dayOfWeek; }
From source file:Main.java
public static int daysOfTwo(Date fDate, Date oDate) { Calendar aCalendar = Calendar.getInstance(); aCalendar.setTime(fDate);/* w w w . ja v a 2s. c o m*/ int day1 = aCalendar.get(Calendar.DAY_OF_YEAR); aCalendar.setTime(oDate); int day2 = aCalendar.get(Calendar.DAY_OF_YEAR); return day2 - day1; }
From source file:Main.java
private static long beginningOfTheDay(Calendar time) { Calendar copy = (Calendar) time.clone(); copy.clear();/*from w w w .j a v a 2 s . co m*/ copy.set(time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH)); return copy.getTimeInMillis(); }
From source file:Main.java
public static boolean isSameDayIgnoreYear(Date date1, Date date2) { Calendar cal1 = buildFromDate(date1); Calendar cal2 = buildFromDate(date2); return cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static String millisToDate(long currentTime) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currentTime); return calendar.get(Calendar.HOUR) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND) + " " + (calendar.get(Calendar.AM_PM) == 0 ? "AM" : "PM"); }