List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static boolean isToday(Calendar cal) { Calendar today = Calendar.getInstance(Locale.getDefault()); return cal.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR) && cal.get(Calendar.YEAR) == today.get(Calendar.YEAR); }
From source file:Main.java
public static String getDate(int hour, int min) { Date d = new Date(); Calendar now = Calendar.getInstance(); now.setTime(d);//from w w w . j av a2 s . co m now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour); now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) + min); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH/mm"); return sdf.format(now.getTime()); }
From source file:Main.java
public static int getDaysLeftInYear() { Calendar calendar = Calendar.getInstance(); return calendar.getActualMaximum(Calendar.DAY_OF_YEAR) - calendar.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
public static String getCurrent() { Calendar calender = Calendar.getInstance(); String minute = ""; if (calender.get(Calendar.MINUTE) < 10) { minute = 0 + "" + calender.get(Calendar.MINUTE); } else {/* w w w. j a v a 2 s. c om*/ minute = "" + calender.get(Calendar.MINUTE); } String created = calender.get(Calendar.YEAR) % 100 + "/" + (calender.get(Calendar.MONTH) + 1) + "/" + calender.get(Calendar.DAY_OF_MONTH) + " " + calender.get(Calendar.HOUR_OF_DAY) + ":" + minute + ""; return created; }
From source file:Main.java
public static boolean isSameMonth(Calendar c1, Calendar c2) { if (c1 == null || c2 == null) return false; return (c1.get(Calendar.ERA) == c2.get(Calendar.ERA) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH)); }
From source file:Main.java
public static boolean isSameDay(Date date1, Date date2) { Calendar cal1 = buildFromDate(date1); Calendar cal2 = buildFromDate(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
private static int normalizeYear(int year) { if (year < 100 && year >= 0) { Calendar now = Calendar.getInstance(); String currentYear = String.valueOf(now.get(Calendar.YEAR)); String prefix = currentYear.substring(0, currentYear.length() - 2); year = Integer.parseInt(String.format(Locale.US, "%s%02d", prefix, year)); }/* ww w . ja v a2 s .c o m*/ return year; }
From source file:Main.java
/** * Takes a date value as used in CPLC Date fields (represented by 2 bytes) * /* www .j ava2 s . com*/ * @param paramByte1 * @param paramByte2 * @throws IllegalArgumentException * @return */ public static Date calculateCplcDate(byte[] dateBytes) throws IllegalArgumentException { if (dateBytes == null || dateBytes.length != 2) { throw new IllegalArgumentException("Error! CLCP Date values consist always of exactly 2 bytes"); } // current time Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int startYearOfCurrentDecade = year - (year % 10); int days = 100 * (dateBytes[0] & 0xF) + 10 * (0xF & dateBytes[1] >>> 4) + (dateBytes[1] & 0xF); if (days > 366) { throw new IllegalArgumentException("Invalid date (or are we parsing it wrong??)"); } Calendar calculatedDate = Calendar.getInstance(); calculatedDate.clear(); calculatedDate.set(Calendar.YEAR, startYearOfCurrentDecade + (0xF & dateBytes[0] >>> 4)); calculatedDate.set(Calendar.DAY_OF_YEAR, days); while (calculatedDate.after(now)) { calculatedDate.add(Calendar.YEAR, -10); } return calculatedDate.getTime(); }
From source file:Main.java
public static int getDaylightSavingsTimeOffset(long timeMs) { int dstOffset = 5; // default not daylight savings time Calendar c = Calendar.getInstance(); c.setTimeInMillis(timeMs);//from w w w . j a v a2 s .c om int day = c.get(Calendar.DATE); int month = c.get(Calendar.MONTH); if ((month > DST_START_MONTH && month < DST_END_MONTH) || (month == DST_START_MONTH && day >= DST_START_DAY) || (month == DST_END_MONTH && day <= DST_END_DAY)) { dstOffset = 4; } return dstOffset; }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();//from w ww .ja va2 s.co m Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }