List of usage examples for java.util Calendar MINUTE
int MINUTE
To view the source code for java.util Calendar MINUTE.
Click Source Link
get
and set
indicating the minute within the hour. From source file:Main.java
public static HashMap<Integer, HashMap<Integer, Integer>> getAvailableTime(HashMap<Date, Date> bookedTimes, Date date) {/*from w w w. j av a2s. c o m*/ HashMap<Integer, HashMap<Integer, Integer>> availableTime = createFullAvailableTime(); HashMap<Date, Date> bookedTimeInOneDate = getBookedTimeInOneDate(bookedTimes, date); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); for (Date keyBooked : bookedTimeInOneDate.keySet()) { startCalendar.setTime(keyBooked); int startHour = startCalendar.get(Calendar.HOUR_OF_DAY); for (int hourIndex = 0; hourIndex < 24; hourIndex++) { if (hourIndex == startHour) { int startMinute = startCalendar.get(Calendar.MINUTE); int endMinute; endCalendar.setTime(bookedTimeInOneDate.get(keyBooked)); int endHour = endCalendar.get(Calendar.HOUR_OF_DAY); //startHour = endHour = hourIndex if (endHour == hourIndex) { endMinute = endCalendar.get(Calendar.MINUTE); removeMinute(startMinute, endMinute, hourIndex, availableTime); } //startHour = hourIndex != endHour else { for (int i = hourIndex; i < endHour + 1; i++) { if (i == hourIndex) { if (startMinute == 0) { availableTime.remove(startHour); } else { removeMinute(startMinute, 59, hourIndex, availableTime); } } else if (i == endHour) { endMinute = endCalendar.get(Calendar.MINUTE); if (endMinute == 59) { availableTime.remove(endHour); } else { removeMinute(0, endMinute, endHour, availableTime); } } else { availableTime.remove(i); } } } } } } return availableTime; }
From source file:Main.java
/** Helper method - creates a Phoenix date <I>String</I> from a Date object. @param dteValue <I>Date</I> object to be converted. @return A <I>String</I> that follows the format "YYYY-MM-DDTHH:NN:SS.00000". *//* w w w. j a v a 2s . c om*/ public static String getXMLStringFromDate(Date dteValue) { if (null == dteValue) return null; Calendar pCalendar = Calendar.getInstance(); pCalendar.setTime(dteValue); // Return the String value. // Special treatment for the month because the current implementation // values January as 0. Code below should work if that ever changes. return pCalendar.get(Calendar.YEAR) + "-" + padNumber(pCalendar.get(Calendar.MONTH) + 1 - Calendar.JANUARY) + "-" + padNumber(pCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + padNumber(pCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + padNumber(pCalendar.get(Calendar.MINUTE)) + ":" + padNumber(pCalendar.get(Calendar.SECOND)); }
From source file:Main.java
public static Date firstTimeOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; }
From source file:Main.java
private static void setEndOfDayToCalendar(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); }
From source file:Main.java
public static String getTime() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); return cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); }
From source file:Main.java
public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.MONTH, monthOfYear - 1); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;/*w ww . j a va 2 s. c o m*/ }
From source file:Main.java
public static Date substractMinutes(Date date, int minutes) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/* ww w.jav a2 s. co m*/ calendar.add(Calendar.MINUTE, -minutes); Date result = calendar.getTime(); return result; }
From source file:Main.java
public static Date startOfDay(Date origDate) { Calendar cal = Calendar.getInstance(); cal.setTime(origDate);// w w w.ja v a2s .co m cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
public static Date getMidnight(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date);//from www.j a va2 s.co m day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); day.add(Calendar.DAY_OF_MONTH, 0); return day.getTime(); }
From source file:Main.java
/** * Packs java time value into an MS-DOS time value. * @param time the time value/*from www . j a v a 2 s . co m*/ * @return the MS-DOS packed time */ public static int packTime(long time) { Calendar c = Calendar.getInstance(); c.setTime(new Date(time)); int seconds = c.get(Calendar.SECOND); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); /* * Here is how MS-DOS packs a time value: * 0-4: seconds (divided by 2 because we only have 5 bits = 32 different numbers) * 5-10: minutes (6 bits = 64 possible values) * 11-15: hours (5 bits = 32 possible values) * * source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724247(v=vs.85).aspx */ return (hours << 11) & (minutes << 5) & (seconds / 2); }