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:com.wiiyaya.framework.common.utils.DateUtils.java
/** * ?23:59:59//from w w w .j a v a2s . c o m * @param date * @return ?? */ public static Date setDayEnd(final Date date) { final Calendar c = Calendar.getInstance(); c.setLenient(false); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); return c.getTime(); }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Integer get24Hour(Calendar calendar) { Integer hour = calendar.get(Calendar.HOUR_OF_DAY); return hour; }
From source file:AIR.Common.Utilities.Dates.java
/** * @param date/*from www. ja v a 2s . c om*/ * @return returns the midnight time for this date e.g. if date is * "10/11/2012 12:10 pm" then this will return "10/11/2012 00:00 am" */ public static Date getStartOfDayDate(Date date) { Calendar calendarInstance = Calendar.getInstance(); calendarInstance.setTime(date); calendarInstance.set(Calendar.HOUR_OF_DAY, 0); calendarInstance.set(Calendar.MINUTE, 0); calendarInstance.set(Calendar.SECOND, 0); return calendarInstance.getTime(); }
From source file:Main.java
/** * Given a calendar (possibly containing only a day of the year), returns the earliest possible * anniversary of the date that is equal to or after the current point in time if the date * does not contain a year, or the date converted to the local time zone (if the date contains * a year.// w w w . ja v a 2 s. co m * * @param target The date we wish to convert(in the UTC time zone). * @return If date does not contain a year (year < 1900), returns the next earliest anniversary * that is after the current point in time (in the local time zone). Otherwise, returns the * adjusted Date in the local time zone. */ public static Date getNextAnnualDate(Calendar target) { final Calendar today = Calendar.getInstance(); today.setTime(new Date()); // Round the current time to the exact start of today so that when we compare // today against the target date, both dates are set to exactly 0000H. today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); final boolean isYearSet = isYearSet(target); final int targetYear = target.get(Calendar.YEAR); final int targetMonth = target.get(Calendar.MONTH); final int targetDay = target.get(Calendar.DAY_OF_MONTH); final boolean isFeb29 = (targetMonth == Calendar.FEBRUARY && targetDay == 29); final GregorianCalendar anniversary = new GregorianCalendar(); // Convert from the UTC date to the local date. Set the year to today's year if the // there is no provided year (targetYear < 1900) anniversary.set(!isYearSet ? today.get(Calendar.YEAR) : targetYear, targetMonth, targetDay); // If the anniversary's date is before the start of today and there is no year set, // increment the year by 1 so that the returned date is always equal to or greater than // today. If the day is a leap year, keep going until we get the next leap year anniversary // Otherwise if there is already a year set, simply return the exact date. if (!isYearSet) { int anniversaryYear = today.get(Calendar.YEAR); if (anniversary.before(today) || (isFeb29 && !anniversary.isLeapYear(anniversaryYear))) { // If the target date is not Feb 29, then set the anniversary to the next year. // Otherwise, keep going until we find the next leap year (this is not guaranteed // to be in 4 years time). do { anniversaryYear += 1; } while (isFeb29 && !anniversary.isLeapYear(anniversaryYear)); anniversary.set(anniversaryYear, targetMonth, targetDay); } } return anniversary.getTime(); }
From source file:br.com.grupofortress.controller.Agendamentos.java
public void terceiraTarefa() { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 9); c.set(Calendar.MINUTE, 40);//from w w w . j a v a 2 s. co m c.set(Calendar.SECOND, 0); Date time = c.getTime(); final Timer t = new Timer(); t.schedule(new TimerTask() { @Override public void run() { System.out.println( "Enviando email _________________________________________________________________ \n"); ClientesDao cli = new ClientesDao(); int qtdSemComunicacao = 0; String msg = "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\" bgcolor=\"#CCCCCC\">\n" + " <tr>\n" + " <td bgcolor=\"#CC0000\"><font size=1 face=\"verdana, arial, helvetica\" color=\"#FFFFFF\"><b>Clientes Sem Comunicao</b></font></td>\n" + " </tr>\n" + " <tr>\n" + " <td bgcolor=\"#F5ECB9\"><table width=\"95%\" cellspacing=\"1\" cellpadding=\"1\" border=\"0\" align=\"center\">\n" + " <tr>\n" + " <td valign=top><font face=\"verdana, arial, helvetica\" size=1><strong>Cdigo</strong></font></td>\n" + " <td><font face=\"verdana, arial, helvetica\" size=1><strong>Nome</strong></font></td>\n" + " <td><font size=\"1\" face=\"verdana, arial, helvetica\"><strong>Ultimo Evento Recebido</strong></font></td>"; for (Cliente cliente : cli.getClientesSemComunicacao("")) { qtdSemComunicacao++; msg = msg + "<tr>" + " <td valign=top><font face=\"verdana, arial, helvetica\" size=1>" + cliente.getCli_codigo() + "</font></td>\n" + " <td><font face=\"verdana, arial, helvetica\" size=1>" + cliente.getCli_nome() + "</font></td>\n" + " <td><font size=\"1\" face=\"verdana, arial, helvetica\">" + Universal.getInstance().calendarToString(cliente.getCli_ultima_comunicacao()) + "</font></td>" + "</tr>"; } msg = msg + " </table></td>\n" + " </tr>\n" + " <tr>\n" + " <td bgcolor=\"#CCCCCC\"><font size=1 face=\"verdana, arial, helvetica\"><b>Total de Clientes sem Comunicao: " + qtdSemComunicacao + "</b></font></td>\n" + "</tr>" + "</table> "; CommonsMail enviaEmail = new CommonsMail(); try { enviaEmail.enviaEmailFormatoHtml(formatString(msg)); } catch (EmailException ex) { Logger.getLogger(GerarTarefasAgendadas.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(GerarTarefasAgendadas.class.getName()).log(Level.SEVERE, null, ex); } } }, time); }
From source file:Main.java
/** * * This method is a utility method to create a new java.sql.Date in one line. * * @param year/*from w ww. ja v a2s.c om*/ * @param month * @param day * * @return a populated java.sql.Date with the year, month, and day specified, and no values for hour, minute, second, * millisecond * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day) { // test for null arguments if (year == null) { throw new IllegalArgumentException("Argument 'year' passed in was null."); } if (month == null) { throw new IllegalArgumentException("Argument 'month' passed in was null."); } if (day == null) { throw new IllegalArgumentException("Argument 'day' passed in was null."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.clear(Calendar.HOUR_OF_DAY); calendar.clear(Calendar.MINUTE); calendar.clear(Calendar.SECOND); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:Main.java
/** * Copy the hour and minutes from a date to another * @param cOrigin Calendar origin where to get the data * @param cDestiny Calendar destiny where to set the data * @return Calendar with hour and minutes from dateOrigin and rest from dateDestiny *///from www. j a v a 2s . c o m public static Calendar copyHourMinute(Calendar cOrigin, Calendar cDestiny) { //check null values if (cOrigin == null && cDestiny == null) { return Calendar.getInstance(); } else if (cOrigin == null) { return cDestiny; } else if (cDestiny == null) { return cOrigin; } //copy year, month and day cDestiny.set(Calendar.HOUR_OF_DAY, cOrigin.get(Calendar.HOUR_OF_DAY)); cDestiny.set(Calendar.MINUTE, cOrigin.get(Calendar.MINUTE)); //return the time of destiny return cDestiny; }
From source file:TimeUtil.java
public static short modFormat(long msecs) { synchronized (statFmtCal) { statFmtCal.setTime(new Date(msecs)); return ((short) (statFmtCal.get(Calendar.HOUR_OF_DAY) * 60 + statFmtCal.get(Calendar.MINUTE))); }//w ww . ja v a 2 s .c o m }
From source file:Main.java
public static File getEmptyFileWithStructuredPath(String course_title, String format) { Calendar calendar = Calendar.getInstance(); int date = calendar.get(Calendar.DATE); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); StringBuffer dateInString = new StringBuffer(); dateInString.append(month);/* w w w .j a v a 2 s .c o m*/ dateInString.append("-"); dateInString.append(date); dateInString.append("-"); dateInString.append(year); StringBuffer timeInString = new StringBuffer(); timeInString.append(hour); timeInString.append("_"); timeInString.append(minute); timeInString.append("_"); timeInString.append(second); Log.d("File Storage", "DateTime : " + dateInString + timeInString); String folderPathInString = Environment.getExternalStorageDirectory().toString() + "/" + LECTURE_HELPER + "/" + course_title + "/" + dateInString + "/"; File folderPath = new File(folderPathInString); if (!folderPath.exists()) { folderPath.mkdirs(); } return new File(folderPath.getPath() + "/" + FILE_NAME_TO_SAVE + timeInString + format); }
From source file:Util.java
private static boolean isMidnight(Calendar calendar) { return (calendar.get(Calendar.HOUR_OF_DAY) == 0) && (calendar.get(Calendar.MINUTE) == 0); }