List of usage examples for java.util Calendar set
public void set(int field, int value)
From source file:Main.java
public static long getStartOfDayMs(int year, int month, int day) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static long getStartOfMonthMs(int year, int month) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, date.getActualMinimum(Calendar.DAY_OF_MONTH)); date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static void trunkYear(Calendar c) { trunkMonth(c); c.set(Calendar.MONTH, 0); }
From source file:Main.java
public static Calendar getCurrentDateWithoutTime() { Calendar cal = Calendar.getInstance(); // locale-specific cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*from w w w . j a v a 2 s .c om*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:Main.java
/** * Get last month first day//from ww w .j av a2 s. c om */ public static int getLastMonthFirstDay() { Calendar lastDate = Calendar.getInstance(); lastDate.set(Calendar.DATE, 1); lastDate.add(Calendar.MONTH, -1); return lastDate.getActualMinimum(Calendar.DAY_OF_MONTH); }
From source file:Main.java
/** * Get relativy days base on today, will return negative and positive * values.//from w w w . j a v a 2s .co m * * @param d * @return */ public static long getRelativeDays(Date d) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long curMilli = c.getTimeInMillis(); c.setTimeInMillis(d.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long dMilli = c.getTimeInMillis(); return (dMilli - curMilli) / (1 * 24 * 3600 * 1000); }
From source file:Main.java
public static ArrayList<Calendar> formatTimesForObject(String string) { ArrayList<Calendar> times = new ArrayList<>(); for (String s : string.split(" ")) { int hour = Integer.valueOf(s.split(":")[0]); int minute = Integer.valueOf(s.split(":")[1]); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); times.add(calendar);/*from w w w . j a va 2 s . c o m*/ } return times; }
From source file:Main.java
public static Date getDateBefore(Date d, int day) { Calendar now = Calendar.getInstance(); now.setTime(d);/*from www .j ava 2s . c om*/ now.set(Calendar.DATE, now.get(Calendar.DATE) - day); return now.getTime(); }
From source file:Main.java
public static String getTimeFromLong(long l) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(l);/*from ww w. j a v a 2s . c o m*/ Calendar t = Calendar.getInstance(); t.set(Calendar.HOUR_OF_DAY, 0); t.set(Calendar.MINUTE, 1); t.set(Calendar.SECOND, 0); if (c.after(t)) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(2); return nf.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + nf.format(c.get(Calendar.MINUTE)); } else { return TIME_NONE; } }
From source file:Main.java
/** * @param days/*w w w . j ava 2 s .c o m*/ * number of days after September 02, 1975 (what happened on this * day?) * @return */ public static Calendar getDayFromQuickLogEntry(int days) { Calendar logDay = GregorianCalendar.getInstance(); logDay.set(Calendar.DAY_OF_MONTH, 2); logDay.set(Calendar.MONTH, Calendar.SEPTEMBER); logDay.set(Calendar.YEAR, 1975); logDay.add(Calendar.DAY_OF_YEAR, days); return logDay; }