List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static boolean IsDiferentDate(Date date1, Date date2) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date1);/*from w w w . ja v a2s . co m*/ int daysInYear1 = calendar.get(Calendar.DAY_OF_YEAR); calendar = Calendar.getInstance(); calendar.setTime(date2); int daysInYear2 = calendar.get(Calendar.DAY_OF_YEAR); if (daysInYear1 != daysInYear2 || date1.getYear() != date2.getYear()) { return true; } return false; }
From source file:Main.java
public static Date getFinanacialDate(Date taxdate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(taxdate);//from w w w. j ava 2s . c o m int yr = calendar.get(Calendar.YEAR); calendar.set(yr, 00, 01); taxdate = calendar.getTime(); return taxdate; }
From source file:Main.java
public static int getWeekIndex(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from w w w .java 2s . c o m*/ return cal.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static String getTimeQuantum(String strDate, String format) { Date data = getDateByFormat(strDate, format); Calendar calendar = Calendar.getInstance(); calendar.setTime(data);//from w w w . j a v a 2s.co m int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour >= 12) { return "PM"; } else { return "AM"; } }
From source file:Main.java
public static boolean isSameAs(int field, Calendar instance, Calendar other) { if (instance == null || other == null) return false; return instance.get(field) == other.get(field); }
From source file:Main.java
public static int getNextMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);/* www .j a va 2 s. co m*/ c.add(Calendar.MONTH, 1); return c.get(Calendar.MONTH); }
From source file:Main.java
public static boolean isCardExpired(String expiry, Date referenceDate) { boolean expired = false; int monthExpiry = Integer.parseInt(expiry.substring(0, 2)); int yearExpiry = 2000 + Integer.parseInt(expiry.substring(2, 4)); Calendar c = Calendar.getInstance(); c.setTime(referenceDate);/*from ww w . j a v a 2 s . co m*/ int monthRef = c.get(Calendar.MONTH) + 1; // months indexed from 0 in java int yearRef = c.get(Calendar.YEAR); if (yearExpiry < yearRef) { expired = true; } else if (yearExpiry == yearRef && monthExpiry < monthRef) { expired = true; } return expired; }
From source file:Main.java
public static int getUpMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);//from w w w . j a v a 2s .c o m c.add(Calendar.MONTH, -1); return c.get(Calendar.MONTH); }
From source file:Main.java
public static String getAge(String fec_nac) { DateFormat df = new SimpleDateFormat("yyyy-mm-dd"); Calendar dob = Calendar.getInstance(); Date d = null;// ww w. j a v a 2 s . c o m try { d = df.parse(fec_nac); } catch (Exception e) { } Calendar today = Calendar.getInstance(); dob.setTime(d); int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR); if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) { age--; } return String.valueOf(age); }
From source file:Main.java
public static int getCurrentYear() { return Calendar.getInstance().get(Calendar.YEAR); }