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
/** * keep year, month & day of calendar * * @param c calendar to be clear// w w w . j a v a 2s .co m */ public static void clearCalendarOffset(Calendar c) { c.set(Calendar.MILLISECOND, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.HOUR_OF_DAY, 0); }
From source file:Main.java
private static boolean isBefore(Calendar date, String time) { try {//from w w w. ja v a2s .co m String[] arr = time.split(":"); int hours = Integer.parseInt(arr[0]); int mins = Integer.parseInt(arr[1]); return (date.get(Calendar.HOUR_OF_DAY) < hours) || (date.get(Calendar.HOUR_OF_DAY) == hours && date.get(Calendar.MINUTE) < mins); } catch (Exception e) { Log.e("Utils.java isBefore", "The supplied times are not properly formatted. Verify that your schedule times follow the hh:mm pattern"); return true; } }
From source file:Main.java
public static void clearTime(Calendar cal) { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*www . j a v a 2 s . c o m*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); }
From source file:Main.java
public static String getTimeFromLong(long l) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(l);//from ww w . j a v a2 s . co 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
public static Date lastTimeOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);// ww w .j av a2s . com cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
public static Date firstTimeOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/* w w w .ja v a2 s. c om*/ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
public static Date getDateFromYearMonthDay(int year, int month, int day) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*w w w .jav a 2 s. c o m*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
/** * Get relativy days base on today, will return negative and positive * values.//from www . ja va2 s .c o 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 int daysSince(final long date) { final Calendar logDate = Calendar.getInstance(); logDate.setTimeInMillis(date);/*from w w w. j a v a 2 s .com*/ logDate.set(Calendar.SECOND, 0); logDate.set(Calendar.MINUTE, 0); logDate.set(Calendar.HOUR_OF_DAY, 0); final Calendar today = Calendar.getInstance(); today.set(Calendar.SECOND, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.HOUR_OF_DAY, 0); return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d); }
From source file:Main.java
public static long getTimesMonthNextStart() { Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, 24); return cal.getTimeInMillis(); }