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.reizes.shiva.utils.CommonUtil.java
/** * ? ? ? ?. ? 00:00:00 /*w ww .jav a2 s. co m*/ * adjustAmount ? -? + ? ?, 0 ? ? */ public static Date getAdjustDayResetTime(Date date, int adjustAmount) { if (date == null) { return null; } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.add(Calendar.DATE, adjustAmount); return cal.getTime(); }
From source file:com.gatf.executor.core.GatfFunctionHandler.java
public static String handleFunction(String function) { if (function.equals(BOOLEAN)) { Random rand = new Random(); return String.valueOf(rand.nextBoolean()); } else if (function.matches(DT_FMT_REGEX)) { Matcher match = datePattern.matcher(function); match.matches();/*from w w w . j av a 2s. c o m*/ SimpleDateFormat format = new SimpleDateFormat(match.group(1)); return format.format(new Date()); } else if (function.matches(DT_FUNC_FMT_REGEX)) { Matcher match = specialDatePattern.matcher(function); match.matches(); String formatStr = match.group(1); String operation = match.group(2); int value = Integer.valueOf(match.group(3)); String unit = match.group(4); SimpleDateFormat format = new SimpleDateFormat(formatStr); try { Date dt = format.parse(format.format(new Date())); Calendar cal = Calendar.getInstance(); cal.setTime(dt); value = (operation.equals(MINUS) ? -value : value); if (unit.equals(YEAR)) { cal.add(Calendar.YEAR, value); } else if (unit.equals(MONTH)) { cal.add(Calendar.MONTH, value); } else if (unit.equals(DAY)) { cal.add(Calendar.DAY_OF_YEAR, value); } else if (unit.equals(HOUR)) { cal.add(Calendar.HOUR_OF_DAY, value); } else if (unit.equals(MINUITE)) { cal.add(Calendar.MINUTE, value); } else if (unit.equals(SECOND)) { cal.add(Calendar.SECOND, value); } else if (unit.equals(MILLISECOND)) { cal.add(Calendar.MILLISECOND, value); } return format.format(cal.getTime()); } catch (Exception e) { throw new AssertionError("Invalid date format specified - " + formatStr); } } else if (function.equals(FLOAT)) { Random rand = new Random(12345678L); return String.valueOf(rand.nextFloat()); } else if (function.equals(ALPHA)) { return RandomStringUtils.randomAlphabetic(10); } else if (function.equals(ALPHANUM)) { return RandomStringUtils.randomAlphanumeric(10); } else if (function.equals(NUMBER_PLUS)) { Random rand = new Random(); return String.valueOf(rand.nextInt(1234567)); } else if (function.equals(NUMBER_MINUS)) { Random rand = new Random(); return String.valueOf(-rand.nextInt(1234567)); } else if (function.equals(NUMBER)) { Random rand = new Random(); boolean bool = rand.nextBoolean(); return bool ? String.valueOf(rand.nextInt(1234567)) : String.valueOf(-rand.nextInt(1234567)); } else if (function.matches(RANDOM_RANGE_REGEX)) { Matcher match = randRangeNum.matcher(function); match.matches(); String min = match.group(1); String max = match.group(2); try { int nmin = Integer.parseInt(min); int nmax = Integer.parseInt(max); return String.valueOf(nmin + (int) (Math.random() * ((nmax - nmin) + 1))); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:nl.xillio.gitbreakers.procrastimaster.server.services.UpdateService.java
private void setNextWorkingDayToMidnight(Update entity) { Calendar calendar = new GregorianCalendar(); calendar.setTime(entity.getNextDay()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); entity.setNextDay(calendar.getTime()); }
From source file:net.groupbuy.controller.admin.SalesController.java
/** * /* w w w .j a va2 s . c o m*/ */ @RequestMapping(value = "/view", method = RequestMethod.GET) public String view(Type type, Date beginDate, Date endDate, Model model) { if (type == null) { type = Type.month; } if (beginDate == null) { beginDate = DateUtils.addMonths(new Date(), -11); } if (endDate == null) { endDate = new Date(); } Map<Date, BigDecimal> salesAmountMap = new LinkedHashMap<Date, BigDecimal>(); Map<Date, Integer> salesVolumeMap = new LinkedHashMap<Date, Integer>(); Calendar beginCalendar = DateUtils.toCalendar(beginDate); Calendar endCalendar = DateUtils.toCalendar(endDate); int beginYear = beginCalendar.get(Calendar.YEAR); int endYear = endCalendar.get(Calendar.YEAR); int beginMonth = beginCalendar.get(Calendar.MONTH); int endMonth = endCalendar.get(Calendar.MONTH); for (int year = beginYear; year <= endYear; year++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); if (type == Type.year) { calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH)); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } else { for (int month = year == beginYear ? beginMonth : calendar.getActualMinimum(Calendar.MONTH); month <= (year == endYear ? endMonth : calendar.getActualMaximum(Calendar.MONTH)); month++) { if (salesAmountMap.size() >= MAX_SIZE) { break; } calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); Date begin = calendar.getTime(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); Date end = calendar.getTime(); BigDecimal salesAmount = orderService.getSalesAmount(begin, end); Integer salesVolume = orderService.getSalesVolume(begin, end); salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO); salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0); } } } model.addAttribute("types", Type.values()); model.addAttribute("type", type); model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); model.addAttribute("salesAmountMap", salesAmountMap); model.addAttribute("salesVolumeMap", salesVolumeMap); return "/admin/sales/view"; }
From source file:emily.util.YTUtil.java
/** * Time until the next google api reset happens (Midnight PT), or 9am GMT * * @return formatted string, eg. "10 minutes form now" *///from ww w .ja v a2 s . c o m public static String nextApiResetTime() { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_MONTH, 0); c.set(Calendar.HOUR_OF_DAY, 9); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return TimeUtil.getRelativeTime( (System.currentTimeMillis() + (c.getTimeInMillis() - System.currentTimeMillis()) % TimeUnit.DAYS.toMillis(1)) / 1000L, false); }
From source file:HSSFDateUtil.java
/** * Given a Date, converts it into a double representing its internal Excel * representation, which is the number of days since 1/1/1900. Fractional days * represent hours, minutes, and seconds. * /*from w ww.j a va 2 s.c o m*/ * @return Excel representation of Date (-1 if error - test for error by * checking for less than 0.1) * @param date * the Date */ public static double getExcelDate(final Date date) { Calendar calStart = new GregorianCalendar(); calStart.setTime(date); // If date includes hours, minutes, and seconds, set // them to 0 // if (calStart.get(Calendar.YEAR) < 1900) // { // return BAD_DATE; // } // else // { // Because of daylight time saving we cannot use // date.getTime() - calStart.getTimeInMillis() // as the difference in milliseconds between 00:00 and 04:00 // can be 3, 4 or 5 hours but Excel expects it to always // be 4 hours. // E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours // and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours final double fraction = (((calStart.get(Calendar.HOUR_OF_DAY) * 60 + calStart.get(Calendar.MINUTE)) * 60 + calStart.get(Calendar.SECOND)) * 1000 + calStart.get(Calendar.MILLISECOND)) / (double) DAY_MILLISECONDS; calStart = dayStart(calStart); return fraction + (double) absoluteDay(calStart) - CAL_1900_ABSOLUTE; }
From source file:uta.ak.usttmp.dmcore.service.impl.MiningTaskServiceImpl.java
@Override public int addMiningTask(MiningTask mt) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startdt = formatter.format(mt.getStartTime()); String enddt = formatter.format(mt.getEndTime()); int count = (int) ((mt.getEndTime().getTime() - mt.getStartTime().getTime()) / (mt.getMiningInterval() * 60 * 60 * 1000)); mt.setQrtzJobTotalCount(count);/* w w w . j a v a2s . c om*/ long taskId = this.doCreateSingleMiningTask(mt); Calendar cal = Calendar.getInstance(); cal.setTime(mt.getStartTime()); cal.add(Calendar.HOUR_OF_DAY, mt.getMiningInterval()); Date jobStartTime = cal.getTime(); String qrtzJobName = this.scheduleJob(taskId, mt.getName(), count, mt.getMiningInterval(), jobStartTime); String updateJobNameSql = "update c_miningtask set qrtz_job_name=? where mme_eid=?"; getJdbcTemplate().update(updateJobNameSql, qrtzJobName, taskId); return 1; }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java
public void testBadTimeResolution() { Calendar c = Calendar.getInstance(); Map<String, Object> params = new HashMap<String, Object>(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 5);/*from ww w. j a v a 2s.c om*/ List<TimePoint> series = new LinkedList<TimePoint>(); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.MINUTE, 12); series.add(new TimePoint(c.getTime(), 8, params)); Map<String, Object> seriesParams = new HashMap<String, Object>(); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } series.clear(); for (int i = 1; i < 5; i += 1) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_WEEK, i); series.add(new TimePoint(c.getTime(), i, params)); } c.set(Calendar.DAY_OF_WEEK, 2); c.set(Calendar.HOUR_OF_DAY, 3); series.add(new TimePoint(c.getTime(), 2, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through okay } catch (GraphException e) { fail(); } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.DAY_OF_WEEK, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a daily resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for weekly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.WEEK_OF_MONTH, 3); series.add(new TimePoint(c.getTime(), 8, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a weekly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for monthly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.set(Calendar.MONTH, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a monthly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for yearly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.add(Calendar.YEAR, 1); series.add(new TimePoint(c.getTime(), 18, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a yearly resolution } catch (GraphException e) { fail(); } }
From source file:es.tekniker.framework.ktek.util.Utils.java
private static Calendar getCalendarUTC() { Calendar c = Calendar.getInstance(); System.out.println("current: " + c.getTime()); TimeZone z = c.getTimeZone(); int offset = z.getRawOffset(); if (z.inDaylightTime(new Date())) { offset = offset + z.getDSTSavings(); }// ww w. ja va2s . co m int offsetHrs = offset / 1000 / 60 / 60; int offsetMins = offset / 1000 / 60 % 60; System.out.println("offsetHrs: " + offsetHrs); System.out.println("offsetMins: " + offsetMins); c.add(Calendar.HOUR_OF_DAY, (-offsetHrs)); c.add(Calendar.MINUTE, (-offsetMins)); System.out.println("GMT Time: " + c.getTime()); return c; }
From source file:TimeUtils.java
public static synchronized StringBuffer appendTime(StringBuffer sb, long timeStamp, boolean millisecond) { if (timeStamp == 0) { sb.append("n/a"); return sb; }/*from w ww.ja va2 s .c o m*/ if (singleCalendar == null) { singleCalendar = Calendar.getInstance(); singleDate = new Date(); } singleDate.setTime(timeStamp); singleCalendar.setTime(singleDate); StringUtils.appendD00(sb, singleCalendar.get(Calendar.HOUR_OF_DAY)).append(':'); StringUtils.appendD00(sb, singleCalendar.get(Calendar.MINUTE)).append(':'); StringUtils.appendD00(sb, singleCalendar.get(Calendar.SECOND)); if (millisecond) { sb.append('.'); StringUtils.appendD000(sb, singleCalendar.get(Calendar.MILLISECOND)); } return sb; }