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
public static String getTimeQuantum(String strDate, String format) { Date data = getDateByFormat(strDate, format); Calendar calendar = Calendar.getInstance(); calendar.setTime(data);//from w w w . j av a 2 s . com int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour >= 12) { return "PM"; } else { return "AM"; } }
From source file:Main.java
public static boolean isInTimeNow(int start, int end) { Calendar calendar = new ThreadLocal<Calendar>() { protected Calendar initialValue() { return Calendar.getInstance(); }/* w w w .j av a 2s .co m*/ }.get(); long current = System.currentTimeMillis(); calendar.setTimeInMillis(current); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); long originToday = calendar.getTimeInMillis(); long distance = current - originToday; if (start <= distance && distance <= end) { return true; } return false; }
From source file:Main.java
/** * Returns Date object of the next day of d. * @return//w w w.j av a 2s . c om */ public static Date getNextDay(Date d) { Calendar c = Calendar.getInstance(); if (d != null) c.setTime(d); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.DAY_OF_MONTH, 1); return c.getTime(); }
From source file:MainClass.java
public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond) { Calendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DATE, day);/*from ww w .j a v a2 s. c o m*/ cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, millisecond); // now convert GregorianCalendar object to Timestamp object return new Timestamp(cal.getTimeInMillis()); }
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);// w w w . ja va 2s. c o m } return times; }
From source file:Main.java
private static void setAlarm(Calendar calendar, String sTime) { String speech[] = sTime.split(" "); String time = speech[0];// w w w . j ava 2s .c om String timeParts[] = time.split(":"); int hour = Integer.parseInt(timeParts[0]); int minute = Integer.parseInt(timeParts[1]); String ampm = speech[1].toUpperCase(); if (ampm.startsWith("P")) { hour += 12; } calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); }
From source file:Main.java
public static long getYearStart() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/*from w w w. ja v a2s.c o m*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:Main.java
public static Date getDateTimeFrom(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, 0); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.YEAR, 0); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); Date ret = calendar.getTime(); return ret;/* w w w . ja va 2s . co m*/ }
From source file:Main.java
public static Bundle bundleCalendar(Calendar cal) { Bundle args = new Bundle(); if (cal == null) cal = Calendar.getInstance(Locale.getDefault()); ;/*from ww w . j a v a 2 s . co m*/ args.putInt("year", cal.get(Calendar.YEAR)); args.putInt("month", cal.get(Calendar.MONTH)); args.putInt("day", cal.get(Calendar.DAY_OF_MONTH)); args.putInt("hour", cal.get(Calendar.HOUR_OF_DAY)); args.putInt("minute", cal.get(Calendar.MINUTE)); return args; }
From source file:Main.java
public static void previousDateString(String dateString) throws ParseException { DateFormat inputDateFormat = new SimpleDateFormat("dd-MM-yyyy"); DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Calendar now = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); Date myDate = inputDateFormat.parse(dateString); calendar.setTime(myDate);/*from w ww. j a v a2 s .co m*/ calendar.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, now.get(Calendar.MINUTE)); String output = outputDateFormat.format(calendar.getTime()); System.out.println(output); }