List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:Main.java
static Calendar toNearestWholeHour(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());//from w w w . j a va 2s .c o m if (c.get(Calendar.MINUTE) >= 30) c.add(Calendar.HOUR, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
static Calendar toNearestWholeMinute(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());/*from w ww . jav a 2s . com*/ if (c.get(Calendar.SECOND) >= 30) c.add(Calendar.MINUTE, 1); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
public static int getYears(int year, int month, int day) { GregorianCalendar cal = new GregorianCalendar(); int y, m, d, noofyears; y = cal.get(Calendar.YEAR);// current year , m = cal.get(Calendar.MONTH);// current month d = cal.get(Calendar.DAY_OF_MONTH);//current day cal.set(year, month, day);// here ur date noofyears = y - cal.get(Calendar.YEAR); if ((m < cal.get(Calendar.MONTH)) || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) { --noofyears;/*from w ww . ja v a 2s .com*/ } try { if (noofyears < 0) throw new IllegalArgumentException("age < 0"); } catch (IllegalArgumentException ile) { ile.printStackTrace(); } System.out.println(noofyears); return noofyears; }
From source file:MainClass.java
public static boolean isLeapYear(int year) { GregorianCalendar gcal = new GregorianCalendar(); return gcal.isLeapYear(year); }
From source file:Main.java
/** * /* w w w. j a v a2 s . c om*/ * @return */ public static long getMillisGMT() { Calendar calendar = new GregorianCalendar(); TimeZone mTimeZone = calendar.getTimeZone(); int offset = mTimeZone.getOffset(System.currentTimeMillis()); return System.currentTimeMillis() - offset; }
From source file:Main.java
/** * /* w w w .j av a2s. c o m*/ * @return */ public static long getMillisGMT() { Calendar calendar = new GregorianCalendar(); TimeZone mTimeZone = calendar.getTimeZone(); int offset = mTimeZone.getRawOffset(); return System.currentTimeMillis() - offset; }
From source file:Main.java
public static Calendar getDateAwareCalendar() { Calendar calendar = new GregorianCalendar(); // Check if the 1st of September is in two weeks. If so we need to download full timetable // for two weeks beginning from the 1st of September in advance. if (calendar.get(Calendar.MONTH) == Calendar.AUGUST && calendar.get(Calendar.DATE) >= 18) { calendar.set(Calendar.MONTH, Calendar.SEPTEMBER); calendar.set(Calendar.DATE, 1); }//from w w w .ja va 2 s . c o m prepareCalendarNoSunday(calendar); return calendar; }
From source file:Main.java
public static boolean isPastDate(String year, String month, String day) { try {//from w ww . j a v a 2s. c o m GregorianCalendar cal = new GregorianCalendar(); cal.setLenient(false); SimpleDateFormat fmDate = new SimpleDateFormat("yyyyMMdd"); String today = fmDate.format(cal.getTime()); cal.clear(); cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); String inputday = fmDate.format(cal.getTime()); if (inputday.compareTo(today) < 0) { return true; } else { return false; } } catch (IllegalArgumentException e) { return false; } }
From source file:Main.java
public static int compareDate(String aDate, String bDate) { String[] strDate;//from w w w .ja va 2 s . co m GregorianCalendar aCal = new GregorianCalendar(); GregorianCalendar bCal = new GregorianCalendar(); if (aDate.indexOf("/") != -1) { strDate = aDate.split("/"); aCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1, Integer.parseInt(strDate[2].trim())); } else if (aDate.indexOf("-") != -1) { strDate = aDate.split("-"); aCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1, Integer.parseInt(strDate[2].trim())); } else if (aDate.length() == 8) { aCal.set(Integer.parseInt(aDate.substring(0, 4)), Integer.parseInt(aDate.substring(4, 6)) - 1, Integer.parseInt(aDate.substring(6, 8))); } else if (aDate.length() == 10) { aCal.set(Integer.parseInt(aDate.substring(0, 4)), Integer.parseInt(aDate.substring(5, 7)) - 1, Integer.parseInt(aDate.substring(8, 10))); } if (bDate.indexOf("/") != -1) { strDate = bDate.split("/"); bCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1, Integer.parseInt(strDate[2].trim())); } else if (bDate.indexOf("-") != -1) { strDate = bDate.split("-"); bCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1, Integer.parseInt(strDate[2].trim())); } else if (bDate.length() == 8) { bCal.set(Integer.parseInt(bDate.substring(0, 4)), Integer.parseInt(bDate.substring(4, 6)) - 1, Integer.parseInt(bDate.substring(6, 8))); } else if (bDate.length() == 10) { bCal.set(Integer.parseInt(bDate.substring(0, 4)), Integer.parseInt(bDate.substring(5, 7)) - 1, Integer.parseInt(bDate.substring(8, 10))); } return aCal.compareTo(bCal); }
From source file:Main.java
/** * * @return//from w w w. ja v a 2s.c o m */ public static String tomorrow() { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(new Date()); gc.add(GregorianCalendar.DATE, 1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(gc.getTime()); }