List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:org.hobbit.utils.rdf.RdfHelper.java
/** * Returns the object as {@link Calendar} of the first triple that has the given * subject and predicate and that can be found in the given model. * * @param model//from ww w.ja va 2 s.c om * the model that should contain the triple * @param subject * the subject of the triple. <code>null</code> works like a * wildcard. * @param predicate * the predicate of the triple. <code>null</code> works like a * wildcard. * @return object of the triple as {@link Calendar} or <code>null</code> if such * a triple couldn't be found or the value can not be read as XSDDate */ public static Calendar getDateValue(Model model, Resource subject, Property predicate) { Calendar result = getCalendarValue(model, subject, predicate, XSDDatatype.XSDdate); if (result != null) { result.setTimeZone(Constants.DEFAULT_TIME_ZONE); } return result; }
From source file:com.lloydtorres.stately.helpers.RaraHelper.java
/** * Determines if the current day in the EST/EDT timezone is a special day. * @return The special day mode/* w w w . j a v a2s.co m*/ */ public static int getSpecialDayStatus() { Calendar cal = new GregorianCalendar(); cal.setTimeZone(SparkleHelper.TIMEZONE_TORONTO); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (month == Calendar.JANUARY && day == 30) { return DAY_STATELY_BIRTHDAY; } else if (month == Calendar.JULY && day == 1) { return DAY_CANADA_DAY; } else if (month == Calendar.OCTOBER && day == 31) { return DAY_HALLOWEEN; } else if (month == Calendar.NOVEMBER && day == 13) { return DAY_NS_BIRTHDAY; } else { return DAY_NORMAL; } }
From source file:com.appeligo.captions.CaptionListener.java
private synchronized static void checkStats() { int interval = 5; // minutes long timestamp = new Date().getTime(); if ((timestamp - lastWrite) > (interval * 60 * 1000)) { lastWrite = timestamp;/*from ww w . j a v a 2 s . c o m*/ String day = Utils.getDatePath(timestamp); if (!day.equals(currentDay)) { if (statsFile != null) { statsFile.println("</table></body></html>"); statsFile.close(); 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 + "/searchprocstats.html"; 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 = "Search 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'>Mem Pre GC</th>" + "<th>GC</th>" + "<th colspan='3'>Mem Post GC</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("<th>Millis</th>"); statsFile.println("<th>Used</th>"); statsFile.println("<th>Committed</th>"); statsFile.println("<th>Max</th>"); statsFile.println("</tr>"); } } 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()); long beforeGC = System.currentTimeMillis(); System.gc(); long elapsed = System.currentTimeMillis() - beforeGC; statsFile.format("<td>%,d</td>", (int) elapsed); memoryBean = ManagementFactory.getMemoryMXBean(); memory = memoryBean.getHeapMemoryUsage(); 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:no.met.jtimeseries.chart.Utility.java
public static int getHourOfDayUTC(Date time) { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTime(time);/* w ww . j av a 2 s .c om*/ return calendar.get(Calendar.HOUR_OF_DAY); }
From source file:no.met.jtimeseries.chart.Utility.java
/** * @param orig/* w w w. jav a2s . com*/ * The orginal date to add hours to * @param hours * The number of hours to add. * @return A new date object with the specified number of hours added to it. */ public static Date getDateWithAddedHours(Date orig, int hours) { Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTime(orig); calendar.add(Calendar.HOUR_OF_DAY, hours); return calendar.getTime(); }
From source file:com.peterphi.std.crypto.keygen.CaHelper.java
private static void setNotBeforeNotAfter(final X509V3CertificateGenerator gen, final int validForYears) { // Make sure the timezone is UTC (non-UTC timezones seem to cause PureTLS some problems, which causes globus problems) Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC")); now.setTimeZone(TimeZone.getTimeZone("UTC")); // Set Not Before to be 48 hours in the past now.add(Calendar.HOUR, -48);/*from w w w.j a va2 s .c o m*/ gen.setNotBefore(now.getTime()); // Set Not After to be 10 years after that now.add(Calendar.YEAR, validForYears); gen.setNotAfter(now.getTime()); }
From source file:org.osaf.caldav4j.util.ICalendarUtils.java
private static void setFields(Date date, int year, int month, int day, int hour, int minutes, int seconds, int milliseconds, TimeZone tz, boolean utc) { Calendar calendar = Calendar.getInstance(); calendar.clear();// w w w. j a v a 2 s . c om calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.setTimeZone(tz == null ? J_TZ_GMT : tz); if (date instanceof DateTime) { if (utc) { ((DateTime) date).setUtc(utc); } else if (tz != null) { ((DateTime) date).setTimeZone(tz); } calendar.set(Calendar.HOUR, hour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); calendar.set(Calendar.MILLISECOND, milliseconds); } date.setTime(calendar.getTimeInMillis()); }
From source file:jp.co.nemuzuka.utils.DateTimeUtils.java
/** * ??./*from www. j a v a 2 s . c o m*/ * ??????Date???? * ????????????????? * ??????????? * @param targetYyyyMM ? * @return index 0:??Date index 1:?Date */ public static List<Date> getStartEndDate4SunDay(String targetYyyyMM) { List<Date> list = getStartEndDate(targetYyyyMM); Date startDate = list.get(0); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(getTimeZone()); //?? while (true) { calendar.setTime(startDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { //????? break; } //1?? startDate = addDays(startDate, -1); } Date endDate = list.get(1); //? while (true) { calendar.setTime(endDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { //????? break; } //1? endDate = addDays(endDate, 1); } List<Date> retList = new ArrayList<Date>(); retList.add(startDate); retList.add(endDate); return retList; }
From source file:com.krawler.common.timezone.Timezone.java
public static String[] getGmtDate(Connection conn, String date1, String userid) throws ServiceException, ParseException { String tzUser = getTimeZone(conn, userid); Calendar calInstance = Calendar.getInstance(); calInstance.setTimeZone(java.util.TimeZone.getTimeZone("GMT" + tzUser)); TimeZone tz = calInstance.getTimeZone(); int temp = tz.getRawOffset(); java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-d HH:mm:ss"); java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-d HH:mm:ss"); java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); java.util.Calendar cal1 = Calendar.getInstance(new SimpleTimeZone(temp, tzUser)); format0.setCalendar(cal0);//from w w w. j a va2 s .com format1.setCalendar(cal1); String dateArr[] = date1.split(" "); if (dateArr.length == 1 || dateArr[1].equals("00:00:00")) { date1 = dateArr[0] + " " + "00:00:01"; } java.util.Date date = format1.parse(date1); String result = format0.format(date); String[] results = result.split(" "); return results; }
From source file:com.krawler.common.timezone.Timezone.java
public static String[] getTzonetoGmt(String date1, String tzUser) throws ServiceException, ParseException { Calendar calInstance = Calendar.getInstance(); calInstance.setTimeZone(java.util.TimeZone.getTimeZone("GMT" + tzUser)); TimeZone tz = calInstance.getTimeZone(); int temp = tz.getRawOffset(); java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-d HH:mm:ss"); java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-d HH:mm:ss"); java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); java.util.Calendar cal1 = Calendar.getInstance(new SimpleTimeZone(temp, tzUser)); format0.setCalendar(cal0);//w w w. j a va 2 s. com format1.setCalendar(cal1); String dateArr[] = date1.split(" "); if (dateArr[1].equals("00:00:00")) { date1 = dateArr[0] + " " + "00:00:01"; } java.util.Date date = format1.parse(date1); String result = format0.format(date); String[] results = result.split(" "); if (results[1].equals("00:00:00")) { results[1] = "00:00:01"; } return results; }