List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:ch.algotrader.service.CalendarServiceImpl.java
/** * gets the weekday of the specified date * @param timeZone/*from w w w.ja v a2s . c o m*/ */ private WeekDay getWeekDay(final Date date, final TimeZone timeZone) { Calendar cal = new GregorianCalendar(); cal.setTimeZone(timeZone); cal.setTime(date); return WeekDay.fromValue(cal.get(Calendar.DAY_OF_WEEK)); }
From source file:captureplugin.drivers.dreambox.connector.DreamboxConnector.java
/** * Add a recording to the Dreambox// w ww . j ava 2 s.c om * * @param dreamboxChannel * the DreamboxChannel for the Program * @param prgTime * add this ProgramTime * @param afterEvent * 0=nothing, 1=standby, 2=deepstandby, 3=auto * @param timezone * TimeZone to use for recording * @return True, if successful */ public boolean addRecording(DreamboxChannel dreamboxChannel, ProgramTime prgTime, int afterEvent, TimeZone timezone) { if (!mConfig.hasValidAddress()) { return false; } try { Calendar start = prgTime.getStartAsCalendar(); start.setTimeZone(timezone); Calendar end = prgTime.getEndAsCalendar(); end.setTimeZone(timezone); String shortInfo = prgTime.getProgram().getShortInfo(); if (shortInfo == null) { shortInfo = ""; } InputStream stream = openStreamForLocalUrl( "/web/tvbrowser?&command=add&action=0" + "&syear=" + start.get(Calendar.YEAR) + "&smonth=" + (start.get(Calendar.MONTH) + 1) + "&sday=" + start.get(Calendar.DAY_OF_MONTH) + "&shour=" + start.get(Calendar.HOUR_OF_DAY) + "&smin=" + start.get(Calendar.MINUTE) + "&eyear=" + end.get(Calendar.YEAR) + "&emonth=" + (end.get(Calendar.MONTH) + 1) + "&eday=" + end.get(Calendar.DAY_OF_MONTH) + "&ehour=" + end.get(Calendar.HOUR_OF_DAY) + "&emin=" + end.get(Calendar.MINUTE) + "&sRef=" + URLEncoder.encode(dreamboxChannel.getName() + "|" + dreamboxChannel.getReference(), "UTF8") + "&name=" + URLEncoder.encode(prgTime.getProgram().getTitle(), "UTF8") + "&description=" + URLEncoder.encode(shortInfo, "UTF8") + "&afterevent=" + afterEvent + "&eit=&disabled=0&justplay=0&repeated=0"); SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); DreamboxStateHandler handler = new DreamboxStateHandler(); saxParser.parse(stream, handler); return (Boolean.valueOf(handler.getState())); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return false; }
From source file:com.knowbout.cc2nlp.server.CCEventServiceImpl.java
private void checkStats() { long timestamp = new Date().getTime(); String day = getFileDate(timestamp); if (!day.equals(currentDay)) { if (statsFile != null) { statsFile.println("</table></body></html>"); statsFile.close();//w w w . j a v a2 s . co m statsFile = null; } currentDay = day; } if (hostname == null) { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostname = "UnknownHost"; } } String dirname = documentRoot + "/stats/" + currentDay + "/" + hostname; String statsFileName = dirname + "/nlpprocstats.html"; int interval = 5; // minutes try { if (statsFile == null) { File dir = new File(dirname); if ((!dir.exists()) && (!dir.mkdirs())) { throw new IOException("Error creating directory " + dirname); } File file = new File(statsFileName); if (file.exists()) { statsFile = new PrintStream(new FileOutputStream(statsFileName, true)); statsFile.println("<tr><td colspan='5'>Restart</td></tr>"); } else { statsFile = new PrintStream(new FileOutputStream(statsFileName)); String title = "NLP Process (tomcat) status for " + currentDay; statsFile.println("<html><head><title>" + title + "</title></head>"); statsFile.println("<body><h1>" + title + "</h1>"); statsFile.println("<table border='1'>"); statsFile.println("<tr>"); statsFile.println( "<th colspan='2'>" + interval + " Minute Intervals</th><th colspan='3'>Memory</th>"); statsFile.println("</tr>"); statsFile.println("<tr>"); statsFile.println("<th>Timestamp</th>"); statsFile.println("<th>Time</th>"); statsFile.println("<th>Used</th>"); statsFile.println("<th>Committed</th>"); statsFile.println("<th>Max<th>"); statsFile.println("</tr>"); } } if ((timestamp - lastWrite) > (interval * 60 * 1000)) { lastWrite = timestamp; Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(timestamp); String time = String.format("%1$tH:%1$tM:%1$tS", cal); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memory = memoryBean.getHeapMemoryUsage(); statsFile.print("<tr>"); statsFile.print("<td>" + timestamp + "</td>"); statsFile.print("<td>" + time + "</td>"); statsFile.format("<td>%,d</td>", memory.getUsed()); statsFile.format("<td>%,d</td>", memory.getCommitted()); statsFile.format("<td>%,d</td>", memory.getMax()); statsFile.println("</tr>"); } } catch (IOException e) { log.error("Error opening or writing to " + statsFileName, e); } }
From source file:eu.openanalytics.rsb.stats.RedisJobStatisticsHandler.java
public void storeJobStatistics(final Job job, final Calendar jobCompletionTime, final long millisecondsSpentProcessing, final String rServiAddress) { runWithJedis(new RedisAction() { public void run(final Jedis jedis) { // ensure application is registered as a statistics producer jedis.sadd(RSB_STATS_APPLICATIONS_SET_KEY, job.getApplicationName()); // add monthstamp to application's set of monthstamps jobCompletionTime.setTimeZone(UTC); final String monthStamp = MONTH_STAMP_FORMAT.format(jobCompletionTime.getTime()); jedis.sadd(RSB_STATS_KEY_PREFIX + job.getApplicationName() + ":monthstamps", monthStamp); // create persisted statistics JSON structure and store it in monthstamp list final Map<String, Object> statsMap = new HashMap<String, Object>(5); statsMap.put("application_name", job.getApplicationName()); statsMap.put("job_id", job.getJobId()); statsMap.put("utc_timestamp", jobCompletionTime.getTimeInMillis()); statsMap.put("time_spent", millisecondsSpentProcessing); statsMap.put("r_servi_address", rServiAddress); if (StringUtils.isNotBlank(job.getUserName())) { statsMap.put("user_name", job.getUserName()); }//w ww . ja v a2 s . c o m final String statsJson = Util.toJson(statsMap); jedis.lpush(RSB_STATS_KEY_PREFIX + job.getApplicationName() + ":" + monthStamp, statsJson); } }); }
From source file:com.ymt.demo1.plates.exportConsult.ExportConsultMainActivity.java
/** * ??//from w w w. ja v a 2 s. co m */ public String getDay() { final Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); // String mYear = String.valueOf(c.get(Calendar.YEAR)); // ?? // String mMonth = String.valueOf(c.get(Calendar.MONTH) + 1);// ?? // String mDay = String.valueOf(c.get(Calendar.DAY_OF_MONTH));// ???? String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK)); if ("1".equals(mWay)) { mWay = ""; } else if ("2".equals(mWay)) { mWay = "1"; } else if ("3".equals(mWay)) { mWay = "2"; } else if ("4".equals(mWay)) { mWay = "3"; } else if ("5".equals(mWay)) { mWay = "4"; } else if ("6".equals(mWay)) { mWay = "5"; } else if ("7".equals(mWay)) { mWay = ""; } return "" + mWay; }
From source file:com.restfb.util.InsightUtilsTest.java
@Test public void prepareQueries30() throws Exception { // produce a set of days in UTC timezone from 1st Nov 9am to 30th Nov 9am // inclusive//from w w w .j a v a 2 s .c om Date d20101101_0900utc = sdfUTC.parse("20101101_0900"); Calendar c = new GregorianCalendar(); c.setTimeZone(UTC_TIMEZONE); c.setTime(d20101101_0900utc); Set<Date> utcDates = new TreeSet<Date>(); for (int dayNum = 1; dayNum <= 30; dayNum++) { utcDates.add(c.getTime()); c.add(Calendar.DAY_OF_MONTH, 1); } assertEquals(30, utcDates.size()); // convert into PST and convert into a list List<Date> datesByQueryIndex = new ArrayList<Date>(convertToMidnightInPacificTimeZone(utcDates)); assertEquals(30, datesByQueryIndex.size()); // Mon Nov 01 00:00:00 2010 PST long day0 = sdfPST.parse("20101101_0000").getTime() / 1000L + 60 * 60 * 24; // Sat Nov 06 00:00:00 2010 PST long day5 = sdfPST.parse("20101106_0000").getTime() / 1000L + 60 * 60 * 24; // Sun Nov 07 00:00:00 2010 PST // //////////// NOTE 7 Nov 2010 was when Summer time turned into Winter time long day6 = sdfPST.parse("20101107_0000").getTime() / 1000L + 60 * 60 * 24; // Mon Nov 08 00:00:00 2010 PST long day7 = sdfPST.parse("20101108_0000").getTime() / 1000L + 60 * 60 * 24; // Tue Nov 30 00:00:00 2010 PST long day29 = sdfPST.parse("20101130_0000").getTime() / 1000L + 60 * 60 * 24; String baseQuery = "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time="; Map<String, String> fqlByQueryIndex = buildQueries(baseQuery, datesByQueryIndex); assertEquals(30, fqlByQueryIndex.size()); assertEquals( "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time=" + day0, fqlByQueryIndex.get("0")); assertEquals( "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time=" + day5, fqlByQueryIndex.get("5")); assertEquals( "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time=" + day6, fqlByQueryIndex.get("6")); assertEquals( "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time=" + day7, fqlByQueryIndex.get("7")); assertEquals( "SELECT metric, value FROM insights WHERE object_id='31698190356' AND metric IN " + "('page_active_users','page_audio_plays') AND period=86400 AND end_time=" + day29, fqlByQueryIndex.get("29")); }
From source file:com.knowbout.epg.processor.ScheduleParser.java
private Date processSchedules(InputStream stream) throws IOException { log.debug("Processing raw text schedules for schedules"); Date firstProgram = null;/* w ww .j a va 2 s. com*/ BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); String line = reader.readLine(); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmm"); dateTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT")); while (line != null) { String[] parts = line.split("\\|", -1); long stationId = Long.parseLong(parts[0]); String programId = parts[1]; Date airTime = null; try { airTime = dateTimeFormat.parse(parts[2] + parts[3]); } catch (ParseException e) { log.error("Error parsing airtime for :" + line); } if (airTime != null) { if (firstProgram == null || firstProgram.after(airTime)) { firstProgram = airTime; } StationLineup lineup = stationIdToLineup.get(stationId); if (lineup != null) { ChannelSchedule schedule = programSchedules.get(new Key(programId, lineup.getCallSign())); if (schedule == null) { schedule = new ChannelSchedule(programId, lineup); programSchedules.put(new Key(programId, lineup.getCallSign()), schedule); } if (schedule != null) { String duration = parts[4]; int durationInMinutes = 0; if (duration.length() == 4) { int hours = Integer.parseInt(duration.substring(0, 2)); int minutes = Integer.parseInt(duration.substring(2, 4)); durationInMinutes = hours * 60 + minutes; } //End time is calculated, but we need it for searching Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTime(airTime); calendar.add(Calendar.MINUTE, durationInMinutes); ScheduleAiring airing = new ScheduleAiring(schedule, stationId, airTime, calendar.getTime(), durationInMinutes, line); schedule.addAiring(airing); } } } line = reader.readLine(); } reader.close(); log.debug("Finished processing raw text schedules for schedules"); return firstProgram; }
From source file:ch.algotrader.service.CalendarServiceImpl.java
/** * truncates the given date by converting it first to the specified timezone and then * taking the year, month, day part and leaving all other fields at zero *///from w w w . j a va2 s . c o m private Date truncateToDayUsingTimeZone(final Date date, final TimeZone tz) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.setTimeZone(tz); Calendar truncateCal = Calendar.getInstance(); truncateCal.set(Calendar.YEAR, cal.get(Calendar.YEAR)); truncateCal.set(Calendar.MONTH, cal.get(Calendar.MONTH)); truncateCal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH)); truncateCal.set(Calendar.HOUR_OF_DAY, 0); truncateCal.set(Calendar.MINUTE, 0); truncateCal.set(Calendar.SECOND, 0); truncateCal.set(Calendar.MILLISECOND, 0); return truncateCal.getTime(); }
From source file:com.dudu.aios.ui.fragment.MainFragment.java
private void initDate() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); String mWay = String.valueOf(c.get(Calendar.DAY_OF_WEEK)); if ("1".equals(mWay)) { mWay = ""; } else if ("2".equals(mWay)) { mWay = ""; } else if ("3".equals(mWay)) { mWay = ""; } else if ("4".equals(mWay)) { mWay = ""; } else if ("5".equals(mWay)) { mWay = ""; } else if ("6".equals(mWay)) { mWay = ""; } else if ("7".equals(mWay)) { mWay = ""; }/* w w w. ja v a 2s. c o m*/ mDateTextView.setText(dateFormat.format(new Date()) + " " + mWay); }
From source file:org.teavm.flavour.json.test.SerializerTest.java
@Test public void writesFormattedDate() { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTimeInMillis(0);//from ww w. j a v a 2s . c o m calendar.set(Calendar.YEAR, 2015); calendar.set(Calendar.MONTH, Calendar.AUGUST); calendar.set(Calendar.DATE, 2); calendar.set(Calendar.HOUR_OF_DAY, 16); calendar.set(Calendar.MINUTE, 25); calendar.set(Calendar.SECOND, 35); Date date = calendar.getTime(); DateFormats formats = new DateFormats(); formats.numeric = date; formats.textual = date; JsonNode node = JSONRunner.serialize(formats); assertTrue("Numeric date is a number", node.get("numeric").isNumber()); assertEquals(date.getTime(), node.get("numeric").asDouble(), 0.1); assertTrue("Textual date is a string", node.get("textual").isTextual()); assertEquals("2015-08-02 16:25:35 Z", node.get("textual").asText()); }