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 void trimTimestamp(Calendar cal) { cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);/* www . j a v a2 s . c om*/ cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); }
From source file:Main.java
/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1 * @param date the calendar instance to convert to a string * @param locale the locale to use when outputting strings such as a day of the week, or month of the year. * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT" *///from w ww.ja v a2 s . co m // package-private - unused static final String convertDateToStringRfc822(Calendar date, Locale locale) { Date a = Date.from(Instant.now()); a.toString(); int day = date.get(Calendar.DAY_OF_MONTH); int hour = date.get(Calendar.HOUR_OF_DAY); int minute = date.get(Calendar.MINUTE); int second = date.get(Calendar.SECOND); String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", " + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale) + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT"; return str; }
From source file:Main.java
public static Time[] getTimesFromScheduleHour(char[] hoursArray) { Calendar begin = Calendar.getInstance(); Calendar end = Calendar.getInstance(); begin.set(Calendar.SECOND, 0); begin.set(Calendar.MILLISECOND, 0); end.set(Calendar.SECOND, 0);//from w w w .jav a2 s.c om end.set(Calendar.MILLISECOND, 0); char beginChar = hoursArray[0]; char endChar = hoursArray[hoursArray.length - 1]; switch (beginChar) { case 'A': begin.set(Calendar.HOUR_OF_DAY, 7); begin.set(Calendar.MINUTE, 30); break; case 'B': begin.set(Calendar.HOUR_OF_DAY, 8); begin.set(Calendar.MINUTE, 20); break; case 'C': begin.set(Calendar.HOUR_OF_DAY, 9); begin.set(Calendar.MINUTE, 10); break; case 'D': begin.set(Calendar.HOUR_OF_DAY, 10); begin.set(Calendar.MINUTE, 10); break; case 'E': begin.set(Calendar.HOUR_OF_DAY, 11); begin.set(Calendar.MINUTE, 10); break; case 'F': begin.set(Calendar.HOUR_OF_DAY, 12); begin.set(Calendar.MINUTE, 0); break; case 'G': begin.set(Calendar.HOUR_OF_DAY, 13); begin.set(Calendar.MINUTE, 0); break; case 'H': begin.set(Calendar.HOUR_OF_DAY, 13); begin.set(Calendar.MINUTE, 50); break; case 'I': begin.set(Calendar.HOUR_OF_DAY, 14); begin.set(Calendar.MINUTE, 50); break; case 'J': begin.set(Calendar.HOUR_OF_DAY, 15); begin.set(Calendar.MINUTE, 40); break; case 'L': begin.set(Calendar.HOUR_OF_DAY, 16); begin.set(Calendar.MINUTE, 40); break; case 'M': begin.set(Calendar.HOUR_OF_DAY, 17); begin.set(Calendar.MINUTE, 30); break; case 'N': begin.set(Calendar.HOUR_OF_DAY, 18); begin.set(Calendar.MINUTE, 30); break; case 'O': begin.set(Calendar.HOUR_OF_DAY, 19); begin.set(Calendar.MINUTE, 20); break; case 'P': begin.set(Calendar.HOUR_OF_DAY, 20); begin.set(Calendar.MINUTE, 20); break; case 'Q': begin.set(Calendar.HOUR_OF_DAY, 21); begin.set(Calendar.MINUTE, 10); break; default: return null; } switch (endChar) { case 'A': end.set(Calendar.HOUR_OF_DAY, 8); end.set(Calendar.MINUTE, 20); break; case 'B': end.set(Calendar.HOUR_OF_DAY, 9); end.set(Calendar.MINUTE, 10); break; case 'C': end.set(Calendar.HOUR_OF_DAY, 10); end.set(Calendar.MINUTE, 10); break; case 'D': end.set(Calendar.HOUR_OF_DAY, 11); end.set(Calendar.MINUTE, 0); break; case 'E': end.set(Calendar.HOUR_OF_DAY, 12); end.set(Calendar.MINUTE, 0); break; case 'F': end.set(Calendar.HOUR_OF_DAY, 12); end.set(Calendar.MINUTE, 50); break; case 'G': end.set(Calendar.HOUR_OF_DAY, 13); end.set(Calendar.MINUTE, 50); break; case 'H': end.set(Calendar.HOUR_OF_DAY, 14); end.set(Calendar.MINUTE, 40); break; case 'I': end.set(Calendar.HOUR_OF_DAY, 15); end.set(Calendar.MINUTE, 40); break; case 'J': end.set(Calendar.HOUR_OF_DAY, 16); end.set(Calendar.MINUTE, 30); break; case 'L': end.set(Calendar.HOUR_OF_DAY, 17); end.set(Calendar.MINUTE, 30); break; case 'M': end.set(Calendar.HOUR_OF_DAY, 18); end.set(Calendar.MINUTE, 20); break; case 'N': end.set(Calendar.HOUR_OF_DAY, 19); end.set(Calendar.MINUTE, 20); break; case 'O': end.set(Calendar.HOUR_OF_DAY, 20); end.set(Calendar.MINUTE, 10); break; case 'P': end.set(Calendar.HOUR_OF_DAY, 21); end.set(Calendar.MINUTE, 10); break; case 'Q': end.set(Calendar.HOUR_OF_DAY, 22); end.set(Calendar.MINUTE, 0); break; default: return null; } return new Time[] { new Time(begin.getTimeInMillis()), new Time(end.getTimeInMillis()) }; }
From source file:Main.java
public static long getTomorrowZeroTimeInMillis() { Calendar calendar = getZeroSecondCalendar(); calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
public static String date2String(Date date, boolean printTime) { Calendar cal = new GregorianCalendar(); cal.setTime(date);//from ww w . j a v a2 s .c o m if (cal.get(Calendar.YEAR) > 10000) { return "---"; } return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "." + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4) + (printTime ? " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":" + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":" + makeTimeString(cal.get(Calendar.SECOND), 2) : ""); }
From source file:Main.java
/** Converts a Macintosh-style timestamp (seconds since * January 1, 1904) into a Java date. The timestamp is * treated as a time in the default localization. * Depending on that localization,//from www .j av a2s . co m * there may be some variation in the exact hour of the date * returned, e.g., due to daylight savings time. * */ public static Date timestampToDate(long timestamp) { Calendar cal = Calendar.getInstance(); cal.set(1904, 0, 1, 0, 0, 0); // If we add the seconds directly, we'll truncate the long // value when converting to int. So convert to hours plus // residual seconds. int hours = (int) (timestamp / 3600); int seconds = (int) (timestamp - (long) hours * 3600L); cal.add(Calendar.HOUR_OF_DAY, hours); cal.add(Calendar.SECOND, seconds); Date dat = cal.getTime(); return dat; }
From source file:Main.java
/** * @param time selected in TimePicker/*from w w w . ja va2 s . c om*/ * @return Converted to calendar */ public static Calendar timeToCalendar(String time) { Calendar calTime = Calendar.getInstance(); calTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); calTime.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); return calTime; }
From source file:Main.java
public static void zeroFromHour(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); }
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". *//*from w ww . j av a 2s . c o m*/ 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
/** * Calculate the Julian Day for a given date using the following formula: * JD = 367 * Y - INT(7 * (Y + INT((M + 9)/12))/4) + INT(275 * M / 9) * + D + 1721013.5 + UT/24/*w w w .ja va 2 s . c o m*/ * * Note that this is only valid for the year range 1900 - 2099. */ public static double calculateJulianDay(Date date) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(date); double hour = cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) / 60.0f + cal.get(Calendar.SECOND) / 3600.0f; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); double jd = 367.0 * year - Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0) + Math.floor(275.0 * month / 9.0) + day + 1721013.5 + hour / 24.0; return jd; }