List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:br.msf.commons.util.AbstractDateUtils.java
/** * Returns the day of week name for the given date. * * @param date The date to be evaluated. * @param locale The desired locale./* www. j a v a 2 s .c o m*/ * @return The day of week name for the given date. */ public static String dayOfWeek(final Object date, final Locale locale) { ArgumentUtils.rejectIfNull(date); return castToCalendar(date).getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, LocaleUtils.getNullSafeLocale(locale)); }
From source file:gov.nasa.arc.spife.ui.table.days.Day.java
public int getDayOfWeek() { synchronized (CALENDAR) { CALENDAR.setTime(date); return CALENDAR.get(Calendar.DAY_OF_WEEK); } }
From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java
protected void setEndDate(int grain) { Calendar end = Calendar.getInstance(); end.set(Calendar.MILLISECOND, 0); end.set(Calendar.SECOND, 0);/*w ww. ja v a 2 s. c o m*/ end.set(Calendar.MINUTE, 0); if (grain == CONSOLIDATION_HOUR) { end.add(Calendar.HOUR_OF_DAY, -hrKeepTime); } else if (grain == CONSOLIDATION_DAY) { end.set(Calendar.HOUR_OF_DAY, 0); end.add(Calendar.DATE, -dayKeepTime); } else if (grain == CONSOLIDATION_WEEK) { end.set(Calendar.HOUR_OF_DAY, 0); while (end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { end.add(Calendar.DATE, -1); } end.add(Calendar.WEEK_OF_YEAR, -weekKeepTime); } else if (grain == CONSOLIDATION_MONTH) { end.set(Calendar.HOUR_OF_DAY, 0); end.set(Calendar.DAY_OF_MONTH, 1); end.add(Calendar.MONTH, -monthKeepTime); } this.endDate = end.getTime(); }
From source file:com.itd.dbmrgdao.TestTime_newscanner.java
private Boolean updateScanFileRoundUp2(BufferedReader br) { try {//from w ww.j a v a 2 s. c om String strLine; SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); ScanDataDate scanDataDateItem = null; Map<String, ScanDataDate> mapScanDatas = new HashMap<String, ScanDataDate>(); String scode = "1985"; // ? ?? String sunday2014 = "2557-01-05"; //default value for check correct setting year Date dateObj = curFormater.parse(sunday2014); Calendar calendar = Calendar.getInstance(); calendar.setTime(dateObj); if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { // system not correct return false; } for (strLine = br.readLine(); strLine != null; strLine = br.readLine()) { String sysid = "", scdate = null, p1Start = null, p2End = null; Boolean isSunday = false; String parts[] = new String[7]; // read data from scan machine by line parts[1] = strLine.substring(3, 11); // date parts[5] = strLine.substring(11, 15); // time parts[5] = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); parts[0] = strLine.substring(18, 27); // systemid // update read data to standard data sysid = parts[0]; scdate = new StringBuffer(parts[1]).insert(parts[1].length() - 2, "-").toString(); scdate = new StringBuffer(scdate).insert(scdate.length() - 5, "-").toString(); // check if sunday must convert to 543 first String temp_scdate = (Integer.toString(Integer.parseInt(scdate.substring(0, 4)) + 543)) .concat(scdate.substring(4, 10)); dateObj = curFormater.parse(temp_scdate); calendar = Calendar.getInstance(); calendar.setTime(dateObj); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { isSunday = true; } // check time from scan machine for in or out ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); //if used in record if (mapScanDatas.containsKey(sysid)) { scanDataDateItem = mapScanDatas.get(sysid); mapScanDatas.remove(sysid); p1Start = scanDataDateItem.getP1start(); p2End = scanDataDateItem.getP2end(); } else { // never used in record scanDataDateItem = null; p1Start = scanRule.getP1start(); p2End = scanRule.getP2end(); } parts[6] = FindInOut(parts[5], scanRule.getP1break_st()); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, parts[5], "01"); } else { p2End = CompareTime(p2End, parts[5], "04"); } // ?? ? ? table scan rule code if (p2End == null || p2End.isEmpty()) { //if not punch out Monthly or Daily will automatic p2End startdart time p2End = scanRule.getP2end(); } else { p2End = CompareTime(p2End, scanRule.getP2end(), "04"); if (scanRule.getCalcot().equals("Y")) { //check if 10 min roundup // >= 50 will 60, < 50 and >= 20 will 30 , < 20 will be 00 p2End = MinRoundUp(p2End); } } // ? if (isSunday) { p2End = scanRule.getP2end(); } scanDataDateItem = new ScanDataDate(sysid, scdate, scode, p1Start, p2End); mapScanDatas.put(sysid, scanDataDateItem); System.out.println("Sysid : " + sysid + ", In : " + scanDataDateItem.getP1start() + ", Out : " + scanDataDateItem.getP2end()); } // create SQL and update data in table UpdateScanData(mapScanDatas); br.close(); return true; } catch (IOException | ParseException e) { JOptionPane.showMessageDialog(null, e); } return false; }
From source file:com.github.notizklotz.derbunddownloader.download.AutomaticIssueDownloadAlarmManager.java
private Calendar calculateNextAlarm(int hourOfDay, int minute) { final Calendar nextAlarm = Calendar.getInstance(); nextAlarm.clear();/*w ww . java2 s . com*/ final Calendar now = Calendar.getInstance(); nextAlarm.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), hourOfDay, minute); //Make sure trigger is in the future if (now.after(nextAlarm)) { nextAlarm.add(Calendar.DAY_OF_MONTH, 1); } //Do not schedule Sundays as the newspaper is not issued on Sundays if ((nextAlarm.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { nextAlarm.add(Calendar.DAY_OF_MONTH, 1); } return nextAlarm; }
From source file:nu.nethome.home.items.web.GraphServlet.java
/** * This is the main enterence point of the class. This is called when a http request is * routed to this servlet./*from w ww. ja v a 2s . co m*/ */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream p = res.getOutputStream(); Date startTime = null; Date stopTime = null; // Analyse arguments String fileName = req.getParameter("file"); if (fileName != null) fileName = getFullFileName(fromURL(fileName)); String startTimeString = req.getParameter("start"); String stopTimeString = req.getParameter("stop"); try { if (startTimeString != null) { startTime = m_Format.parse(startTimeString); } if (stopTimeString != null) { stopTime = m_Format.parse(stopTimeString); } } catch (ParseException e1) { e1.printStackTrace(); } String look = req.getParameter("look"); if (look == null) look = ""; TimeSeries timeSeries = new TimeSeries("Data", Minute.class); // Calculate time window Calendar cal = Calendar.getInstance(); Date currentTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startOfDay = cal.getTime(); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startOfWeek = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, 1); Date startOfMonth = cal.getTime(); cal.set(Calendar.MONTH, Calendar.JANUARY); Date startOfYear = cal.getTime(); // if (startTime == null) startTime = startOfWeek; if (stopTime == null) stopTime = currentTime; if (startTime == null) startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L); try { // Open the data file File logFile = new File(fileName); Scanner fileScanner = new Scanner(logFile); Long startTimeMs = startTime.getTime(); Long month = 1000L * 60L * 60L * 24L * 30L; boolean doOptimize = true; boolean justOptimized = false; try { while (fileScanner.hasNext()) { try { // Get next log entry String line = fileScanner.nextLine(); if (line.length() > 21) { // Adapt the time format String minuteTime = line.substring(0, 16).replace('.', '-'); // Parse the time stamp Minute min = Minute.parseMinute(minuteTime); // Ok, this is an ugly optimization. If the current time position in the file // is more than a month (30 days) ahead of the start of the time window, we // quick read two weeks worth of data, assuming that there is 4 samples per hour. // This may lead to scanning past start of window if there are holes in the data // series. if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) { for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) { fileScanner.nextLine(); } justOptimized = true; continue; } // Detect if we have scanned past the window start position just after an optimization scan. // If this is the case it may be because of the optimization. In that case we have to switch // optimization off and start over. if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) { logFile = new File(fileName); fileScanner = new Scanner(logFile); doOptimize = false; continue; } justOptimized = false; // Check if value is within time window if ((min.getFirstMillisecond() > startTimeMs) && (min.getFirstMillisecond() < stopTime.getTime())) { // Parse the value double value = Double.parseDouble((line.substring(20)).replace(',', '.')); // Add the entry timeSeries.add(min, value); doOptimize = false; } } } catch (SeriesException se) { // Bad entry, for example due to duplicates at daylight saving time switch } catch (NumberFormatException nfe) { // Bad number format in a line, try to continue } } } catch (Exception e) { System.out.println(e.toString()); } finally { fileScanner.close(); } } catch (FileNotFoundException f) { System.out.println(f.toString()); } // Create a collection for plotting TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(timeSeries); JFreeChart chart; int xSize = 750; int ySize = 450; // Customize colors and look of the Graph. if (look.equals("mobtemp")) { // Look for the mobile GUI chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false); XYPlot plot = chart.getXYPlot(); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); xSize = 175; ySize = 180; } else { // Create a Chart with time range as heading SimpleDateFormat localFormat = new SimpleDateFormat(); String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime); chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false); Paint background = new Color(0x9D8140); chart.setBackgroundPaint(background); TextTitle title = chart.getTitle(); // fix title Font titleFont = title.getFont(); titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0); title.setFont(titleFont); title.setPaint(Color.darkGray); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.darkGray); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); plot.setRangeGridlinePaint(Color.darkGray); XYItemRenderer renderer = plot.getRenderer(0); renderer.setSeriesPaint(0, Color.darkGray); xSize = 750; ySize = 450; } try { res.setContentType("image/png"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); res.setStatus(HttpServletResponse.SC_OK); ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } p.flush(); p.close(); return; }
From source file:DateUtil.java
public static String formatHTTPDate(Date date) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT+0")); cal.setTime(date);//from w ww . ja v a 2 s . c o m return DAY_OF_WEEK[cal.get(Calendar.DAY_OF_WEEK) - 1] + ", " + cal.get(Calendar.DAY_OF_MONTH) + " " + MONTH[cal.get(Calendar.MONTH)] + " " + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND) + " GMT"; //Tue%2C+27+Mar+2007+22%3A55%3A48+GMT }
From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresSameDayFuture() throws Exception { Calendar actual = Calendar.getInstance(); actual.add(Calendar.MINUTE, 1); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/* ww w . j av a 2 s. c om*/ int dayOfWeek = expected.get(Calendar.DAY_OF_WEEK); properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, dayOfWeek); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(dayOfWeek, actual.get(Calendar.DAY_OF_WEEK)); }
From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java
@Override public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { log.debug("encodeEnd - component=\"" + component + "\"."); RendererUtils.checkParamValidity(facesContext, component, HtmlOcupationCalendar.class); HtmlOcupationCalendar inputCalendar = (HtmlOcupationCalendar) component; Locale currentLocale = facesContext.getViewRoot().getLocale(); Date value = null;//from ww w. j a v a 2 s. c o m Calendar timeKeeper = Calendar.getInstance(currentLocale); timeKeeper.setTime(new Date()); try { value = new CalendarDateTimeConverter().getAsDate(facesContext, inputCalendar); timeKeeper.setTime(value); } catch (IllegalArgumentException i) { log.warn("encodeEnd - IllegalArgumentException", i); } if (log.isDebugEnabled()) { log.debug("encodeEnd - timeKeeper=\"" + timeKeeper.getTime() + "\"."); } DateFormatSymbols symbols = new DateFormatSymbols(currentLocale); String[] weekdays = mapShortWeekdays(symbols); int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH); int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH); if (currentDay > lastDayInMonth) currentDay = lastDayInMonth; timeKeeper.set(Calendar.DAY_OF_MONTH, 1); int weekDayOfFirstDayOfMonth = mapCalendarDayToCommonDay(timeKeeper.get(Calendar.DAY_OF_WEEK)); int weekStartsAtDayIndex = mapCalendarDayToCommonDay(timeKeeper.getFirstDayOfWeek()); ResponseWriter writer = facesContext.getResponseWriter(); HtmlRendererUtils.writePrettyLineSeparator(facesContext); HtmlRendererUtils.writePrettyLineSeparator(facesContext); // render table writer.startElement(HTML.TABLE_ELEM, component); HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.UNIVERSAL_ATTRIBUTES); HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.EVENT_HANDLER_ATTRIBUTES); writer.flush(); HtmlRendererUtils.writePrettyLineSeparator(facesContext); // render days writeDays(facesContext, writer, inputCalendar, timeKeeper, currentDay, weekStartsAtDayIndex, weekDayOfFirstDayOfMonth, lastDayInMonth, weekdays); writer.endElement(HTML.TABLE_ELEM); }
From source file:strat.mining.multipool.stats.builder.CoinshiftStatsBuilder.java
/** * Clean the stats all 10 minutes. Clean the stats that are older than 5 * days./*from w w w . j a v a 2s .c om*/ */ @Scheduled(cron = "0 5/10 * * * *") public void cleanStats() { LOGGER.debug("Clean the stats."); Calendar calendar = GregorianCalendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -7); long startTime = System.currentTimeMillis(); int nbDeleted = globalStatsDao.deleteGlobalStatsBefore(calendar.getTime()); PERF_LOGGER.info("{} Global Stats cleaned done in {} ms.", nbDeleted, System.currentTimeMillis() - startTime); startTime = System.currentTimeMillis(); nbDeleted = addressStatsDao.deleteAddressStatsBefore(calendar.getTime()); PERF_LOGGER.info("{} Addresses Stats cleaned done in {} ms.", nbDeleted, System.currentTimeMillis() - startTime); }