List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:Main.java
public static java.util.Date getDate(int y, int m, int d, boolean inclusive) { java.util.Date dt = null;/* ww w . jav a 2s . c om*/ Calendar c = Calendar.getInstance(); c.clear(); if (c.getActualMinimum(1) <= y && y <= c.getActualMaximum(1)) { c.set(1, y); if (c.getActualMinimum(2) <= m && m <= c.getActualMaximum(2)) { c.set(2, m); if (c.getActualMinimum(5) <= d && d <= c.getActualMaximum(5)) c.set(5, d); } if (inclusive) { c.add(5, 1); c.add(14, -1); } dt = c.getTime(); } return dt; }
From source file:Main.java
public static Calendar getEmptyCalendarGreenwich() { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Etc/Greenwich")); calendar.clear(); return calendar; }
From source file:Main.java
public static Date getDate(String t, String pattern) { SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault()); try {/*from w ww . ja v a 2 s. com*/ Date date = dateFormat.parse(t); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(date); return date; } catch (ParseException e) { return null; } }
From source file:Main.java
static void setDate(Calendar cal, int month, int date, boolean endOfDay) { cal.clear(); cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); if (endOfDay) { cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); } else {//from w w w . j av a 2s . com cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); } }
From source file:Main.java
/** * Creates a Calendar instance for the given year, month (1-based), and day * (1-based) in the default time zone/*from www. j av a2 s .co m*/ */ public static Calendar createDate(int year, int month, int day) { Calendar date = Calendar.getInstance(); date.clear(); date.set(year, month - 1, day); // Months start at 0 for Calendar! return date; }
From source file:org.hibersap.util.DateUtil.java
public static Date newDate(final int year, final int month, final int date, final int hourOfDay, final int minute, final int second) { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(year, month, date, hourOfDay, minute, second); return cal.getTime(); }
From source file:Main.java
/** * Takes a date value as used in CPLC Date fields (represented by 2 bytes) * /* ww w . j a v a 2 s .co m*/ * @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
/** * Creates a Calendar instance for the given year, month (1-based), and day * (1-based) in the given time zone/*from ww w . j a v a 2 s .c om*/ */ public static Calendar createDate(TimeZone timeZone, int year, int month, int day) { Calendar date = Calendar.getInstance(timeZone); date.clear(); date.set(year, month - 1, day); // Months start at 0 for Calendar! return date; }
From source file:Main.java
/** * Calculates the number of days between Epoch and the given date. * * @param date the date.// w w w . jav a2 s . co m * @return the number of days between Epoch and the given date. */ public static int daysSince1900(Date date) { final Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(1900, 0, 1); return daysBetween(calendar.getTime(), date); }
From source file:Main.java
public static void setToFirstDay(Calendar calendar) { int year = getYear(calendar); int month = getMonth(calendar); calendar.clear(); calendar.set(year, month, 1);//from w w w. j a v a 2s . c om }