List of usage examples for java.util Calendar HOUR_OF_DAY
int HOUR_OF_DAY
To view the source code for java.util Calendar HOUR_OF_DAY.
Click Source Link
get
and set
indicating the hour of the day. From source file:Main.java
static void setDate(Calendar cal, int month, int date) { cal.clear();/* w w w. j a va 2 s . c o m*/ cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); 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
public static HashMap<Integer, HashMap<Integer, Integer>> getAvailableTime(HashMap<Date, Date> bookedTimes, Date date) {/* w w w. j a va2 s. co 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
public static String createJcFileName() { Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); int y = c.get(Calendar.YEAR); int m = c.get(Calendar.MONTH); int d = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); return y + "-" + m + "-" + d + "-" + hour + "-" + minute + "-" + second; }
From source file:Main.java
public static String convertUtc2LocalPro(String utcTime) { if (TextUtils.isEmpty(utcTime)) { return ""; }//from w w w .j a v a2 s . c o m // 2014-10-24T02:58:05.932Z SimpleDateFormat utcFormatter, localFormatter; utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); Date date; Calendar cal = Calendar.getInstance(); try { date = utcFormatter.parse(utcTime); cal.setTime(date); } catch (ParseException e) { e.printStackTrace(); } cal.add(Calendar.HOUR_OF_DAY, +8); date = cal.getTime(); localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); return localFormatter.format(date); }
From source file:ConversionUtil.java
/** * convert into java.sql.Time (or into java.util.Calendar * /*from w ww . ja va 2 s.c o m*/ * @param date * The date containing the time. * @param am * Whether this should be am (true) or pm (false) * @return */ public static Time convertDateToTime(Date date, boolean am) { if (date == null) { return null; } Calendar cal = new GregorianCalendar(); cal.setTime(date); int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); if (am) { // Check to make sure that the hours are indeed am hours if (hourOfDay > 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12); date.setTime(cal.getTimeInMillis()); } } else { // Check to make sure that the hours are indeed pm hours if (cal.get(Calendar.HOUR_OF_DAY) < 11) { cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12); date.setTime(cal.getTimeInMillis()); } } return new Time(date.getTime()); }
From source file:Main.java
/** * // w w w . j av a 2s. co m * @return Hour of the Day in 24 hours format */ public static int getCurrentHours() { return Calendar.getInstance().get(Calendar.HOUR_OF_DAY); }
From source file:Main.java
public static void moveToCalendarDayJust(Calendar cal) { // 2011/11/17 00:00:00.000 moveToCalendarDayJust(cal, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); }
From source file:Main.java
public static long getTodayZeroTimeInMillis() { Calendar calendar = getZeroSecondCalendar(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
static void setDate(Calendar cal, int month, int date, boolean endOfDay) { cal.clear();// www.ja v a2 s. com 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 { 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
public static Date firstTimeOfDate(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); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; }