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:Utils.java
public static Date getEndOfDay(Date day, Calendar cal) { if (day == null) day = new Date(); cal.setTime(day);/*w ww .ja v a 2 s .co m*/ cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
/** * @param startDateTime/* w w w. j a v a 2 s . c om*/ * @param endDateTime * @return the difference in hours between the second timestamp and first */ public static double getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime) { int difference = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDateTime); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDateTime); // First, get difference in whole days Calendar startCompare = Calendar.getInstance(); startCompare.setTime(startDateTime); startCompare.set(Calendar.HOUR_OF_DAY, 0); startCompare.set(Calendar.MINUTE, 0); Calendar endCompare = Calendar.getInstance(); endCompare.setTime(endDateTime); endCompare.set(Calendar.HOUR_OF_DAY, 0); endCompare.set(Calendar.MINUTE, 0); return (endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (60.0000 * 60.0000 * 1000.0000); }
From source file:Main.java
/** * @param startDateTime//from ww w . ja v a 2 s. c o m * @param endDateTime * @return the difference in days between the second timestamp and first */ public static double getDifferenceInDays(Timestamp startDateTime, Timestamp endDateTime) { int difference = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDateTime); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDateTime); // First, get difference in whole days Calendar startCompare = Calendar.getInstance(); startCompare.setTime(startDateTime); startCompare.set(Calendar.HOUR_OF_DAY, 0); startCompare.set(Calendar.MINUTE, 0); startCompare.set(Calendar.SECOND, 0); startCompare.set(Calendar.MILLISECOND, 0); Calendar endCompare = Calendar.getInstance(); endCompare.setTime(endDateTime); endCompare.set(Calendar.HOUR_OF_DAY, 0); endCompare.set(Calendar.MINUTE, 0); endCompare.set(Calendar.SECOND, 0); endCompare.set(Calendar.MILLISECOND, 0); return (endCompare.getTimeInMillis() - startCompare.getTimeInMillis()) / (24 * 60 * 60 * 1000); }
From source file:com.joken.common.utils.ConverterUtils.java
/** * ?/*from www . j a va 2 s .co m*/ * * @param time * :08:30:00 * @param separator * : * @return */ public static Long string2TimeSeconds(String time, String separator) { Calendar cl = Calendar.getInstance(); String[] times = time.split(separator); cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0])); cl.set(Calendar.MINUTE, Integer.valueOf(times[1])); cl.set(Calendar.SECOND, Integer.valueOf(times[2])); cl.set(Calendar.MILLISECOND, 0); return cl.getTimeInMillis() / 1000; }
From source file:Main.java
public static Calendar createCalendar(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); return calendar; }
From source file:Main.java
protected static String toString(GregorianCalendar g1) { StringBuilder buffer = new StringBuilder(); buffer.append(//from w ww .j a v a 2s . c om g1.get(Calendar.YEAR) + "/" + (g1.get(Calendar.MONTH) + 1) + "/" + g1.get(Calendar.DAY_OF_MONTH)); buffer.append(" "); buffer.append(g1.get(Calendar.HOUR_OF_DAY) + ":" + g1.get(Calendar.MINUTE) + ":" + g1.get(Calendar.SECOND) + "." + g1.get(Calendar.MILLISECOND)); return buffer.toString(); }
From source file:Main.java
@NonNull static Date convertDate(int date, int time) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 1997); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, time / 60); calendar.set(Calendar.MINUTE, time % 60); calendar.add(Calendar.DATE, date); return calendar.getTime(); }
From source file:Main.java
public static int getCurrentHourColor() { final int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); return Color.parseColor(BACKGROUND_SPECTRUM[hourOfDay]); }
From source file:Main.java
public Main() { JSpinner m_dateSpinner;//from w w w.j av a 2 s . c om SpinnerDateModel m_dateSpinnerModel; Calendar rightNow = Calendar.getInstance(); Date current = rightNow.getTime(); rightNow.set(Calendar.HOUR_OF_DAY, -24); Date start = rightNow.getTime(); rightNow.set(Calendar.HOUR_OF_DAY, 48); Date end = rightNow.getTime(); int step = Calendar.HOUR_OF_DAY; m_dateSpinnerModel = new SpinnerDateModel(current, start, end, step); m_dateSpinner = new JSpinner(m_dateSpinnerModel); add(m_dateSpinner); }
From source file:Main.java
public static int[] getTime(long time, String timeZone) { Calendar c = Calendar.getInstance(); if (timeZone != null && timeZone.length() != 0) { TimeZone tz = TimeZone.getTimeZone(timeZone); c = Calendar.getInstance(tz); }// w w w. j a va 2 s .co m c.setTimeInMillis(time); 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 new int[] { y, m, d, hour, minute, second }; }