List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:Main.java
public static Calendar initCalendar(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//w ww. jav a 2 s .co m calendar.set(Calendar.HOUR, 10); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:Main.java
public static String getTimeString(long millitm) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(millitm);/*from w ww . ja v a2 s. c o m*/ return (setZeroPad(cal.get(Calendar.HOUR)) + ":" + setZeroPad(cal.get(Calendar.MINUTE)) + ":" + setZeroPad(cal.get(Calendar.SECOND))); }
From source file:Main.java
public static String getDate(int hour, int min) { Date d = new Date(); Calendar now = Calendar.getInstance(); now.setTime(d);/* w ww . j a va 2 s . c o m*/ now.set(Calendar.HOUR, now.get(Calendar.HOUR) + hour); now.set(Calendar.MINUTE, now.get(Calendar.MINUTE) + min); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH/mm"); return sdf.format(now.getTime()); }
From source file:Main.java
public static Date endOfThisMonth() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR, calendar.getActualMaximum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }
From source file:Main.java
public static Date beginOfThisMonth() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR, calendar.getActualMinimum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); return calendar.getTime(); }
From source file:Main.java
private static long calcTimeBettwenZeroAndNow() { Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.setTimeInMillis(System.currentTimeMillis()); int currentHour = calendar.get(calendar.HOUR); calendar.add(Calendar.HOUR, 24 - currentHour); return calendar.getTimeInMillis(); }
From source file:Main.java
static Calendar toNearestWholeHour(Calendar d) { Calendar c = new GregorianCalendar(); c.setTime(d.getTime());// www . j ava2 s. co m if (c.get(Calendar.MINUTE) >= 30) c.add(Calendar.HOUR, 1); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c; }
From source file:Main.java
public static List<Integer> getAllDayInMonth(int month, int year) { List<Integer> listDate = new ArrayList<Integer>(); Calendar calendar = Calendar.getInstance(); calendar.set(year, month, 1);/*w w w .j a v a 2 s . c o m*/ calendar.clear(Calendar.HOUR); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); int totalDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); for (int i = 1; i <= totalDays; i++) { listDate.add(i); } return listDate; }
From source file:Main.java
public static Date getNearestFutureDateWithHour(int hourOfDay) { Calendar cal = Calendar.getInstance(); int hourOfDayNow = cal.get(Calendar.HOUR_OF_DAY); if (hourOfDayNow > hourOfDay) { cal.add(Calendar.DAY_OF_MONTH, 1); }//from ww w . j a v a2s . co m cal.set(Calendar.HOUR, hourOfDay); return cal.getTime(); }
From source file:Main.java
public static Date buildShiftEndTime(int startHour, int startMin, int startAmPm, int endHour, int endMin, int endAmPm) { endHour = endHour == 12 ? 0 : endHour; calendar.clear();//w w w .j av a2 s . c om calendar.set(Calendar.HOUR, endHour); calendar.set(Calendar.MINUTE, endMin); calendar.set(Calendar.AM_PM, endAmPm); if (startAmPm == Calendar.PM && endAmPm == Calendar.AM) { calendar.add(Calendar.DAY_OF_MONTH, 1); } return calendar.getTime(); }