List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static int getCurMonth() { return Calendar.getInstance().get(Calendar.MONTH) + 1; }
From source file:Main.java
/** * @param date/*from w w w . j a v a 2s.c o m*/ * @return */ private static String getDayFromDate(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); }
From source file:Main.java
public static boolean isSameYear(Date targetTime, Date compareTime) { Calendar tarCalendar = Calendar.getInstance(); tarCalendar.setTime(targetTime);//from www. ja va 2 s.co m int tarYear = tarCalendar.get(Calendar.YEAR); Calendar compareCalendar = Calendar.getInstance(); compareCalendar.setTime(compareTime); int comYear = compareCalendar.get(Calendar.YEAR); return tarYear == comYear; }
From source file:Main.java
public static String createCCPFileName() { Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); int y = c.get(Calendar.YEAR); int m = c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second; }
From source file:Main.java
/** * @param date//from w ww. j a va 2 s. c o m * @return Returns year of the argument date. */ private static String getYearFromDate(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return String.valueOf(cal.get(Calendar.YEAR)); }
From source file:Main.java
public static String getWochentagFromSystemDate() { Calendar rightNow = Calendar.getInstance(TimeZone.getDefault()); int dayOfWeek = rightNow.get(Calendar.DAY_OF_WEEK); switch (dayOfWeek) { case 1://w w w . j a v a 2s. co m return "Sonntag"; case 2: return "Montag"; case 3: return "Dienstag"; case 4: return "Mittwoch"; case 5: return "Donnerstag"; case 6: return "Freitag"; case 7: return "Samstag"; } return ""; }
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
/** * Is a dateTime today//from w ww . j av a2 s .c o m * @param dateTimeString in format 2012-10-15T08:17:00 * @return true if today * */ public static boolean isToday(String depDateTime) { boolean isToday = false; Calendar depDate = parseCalendarString(depDateTime); int depDay = depDate.get(Calendar.DAY_OF_MONTH); Calendar now = getTimeNow(); int nowDay = now.get(Calendar.DAY_OF_MONTH); if (depDay == nowDay) { isToday = true; } return isToday; }
From source file:Main.java
public static String getTimeStamp(long l) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(l);//from w w w . ja v a 2s .com return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4) + " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2); }
From source file:Main.java
/** * @param date/*from ww w. j av a 2 s. co m*/ * @return Returns month of the argument date. The returned values is based * on zero-index i.e. for month January, the values returned is "0" */ private static String getMonthFromDate(Date date) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); return String.valueOf(cal.get(Calendar.MONTH)); }