List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:GmtDate.java
/** * Description of the Method/*from w w w . java2s. co m*/ * * @param date Description of the Parameter * @return Description of the Return Value */ public final static String yyyydddFormat(Date date) { yyyydddFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); fullString = yyyydddFormatter.format(date); return fullString.substring(0, 7); // makes new string }
From source file:com.ccoe.build.alerts.pfdash.PfDashJob.java
public void run(File file) { String[] location = ServiceConfig.get("pfdash.db.host").split(";"); List<String> locationList = Arrays.asList(location); int port = ServiceConfig.getInt("pfdash.db.port"); String dbname = ServiceConfig.get("pfdash.db.name"); DB db = null;/*from ww w .j a v a2 s .com*/ Date date = new Date(); Date currentStartTime = DateUtils.getUTCOneDayBack(date); Date currentEndTime = DateUtils.getUTCMidnightZero(date); Condition current = new Condition(); current.setStartDate(currentStartTime); current.setEndDate(currentEndTime); Date previousStartTime = DateUtils.getUTCOneWeekBack(currentStartTime); Date previousEndTime = DateUtils.getUTCOneWeekBack(currentEndTime); Condition previous = new Condition(); previous.setStartDate(previousStartTime); previous.setEndDate(previousEndTime); File parentDirectory = null; Time time = new Time(); TimeZone timeZone = TimeZone.getDefault(); TimeZone utcTimeZone = TimeZone.getTimeZone("UTC"); time.setQueryStart(DateUtils.getDateTimeString(currentStartTime, utcTimeZone)); time.setQueryEnd(DateUtils.getDateTimeString(currentEndTime, utcTimeZone)); boolean warning = false; EmailSender rlb = null; try { db = Connector.connectDB(locationList, port, dbname); db.slaveOk(); parentDirectory = new File(PfDashJob.class.getResource("/").toURI()); File xmlFile = new File(parentDirectory, "alert_kpi_threshold.xml"); if (!xmlFile.exists()) { throw new FileNotFoundException(); } Compare com = new Compare(xmlFile, db); AlertResult ar = com.judgeRules(current, previous); time.setSend(DateUtils.getDateTimeString(date, timeZone)); System.out.println("Email sentTime: " + date); rlb = new EmailSender(ar, time); for (SingleResult singleResult : ar.getResultlist()) { if (!"#CACACA".equals(singleResult.getColor())) { warning = true; } } rlb.sendMail(file, warning); } catch (Exception e) { e.printStackTrace(); String trace = ExceptionUtils.getStackTrace(e); rlb = new EmailSender(); rlb.sendMail(trace, warning); System.out.println("[INFO]: Fail to send pfDash alert email, and an exception email has been send. "); } }
From source file:net.netheos.pcsapi.providers.hubic.SwiftTest.java
@Test public void testParseLastModified() { // Check we won't break if a header is missing : JSONObject json = new JSONObject(); Date timestamp = Swift.parseLastModified(json); assertNull(timestamp);//w w w .j a v a 2 s. c om json.put("last_modified", "2014-02-12T16:13:49.346540"); // this is UTC timestamp = Swift.parseLastModified(json); assertNotNull(timestamp); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(timestamp); assertEquals(2014, cal.get(Calendar.YEAR)); assertEquals(Calendar.FEBRUARY, cal.get(Calendar.MONTH)); assertEquals(12, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(16, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(13, cal.get(Calendar.MINUTE)); assertEquals(49, cal.get(Calendar.SECOND)); assertEquals(346, cal.get(Calendar.MILLISECOND)); checkLastModified("2014-02-12T16:13:49.346540", cal.getTime()); checkLastModified("2014-02-12T16:13:49.3460", cal.getTime()); checkLastModified("2014-02-12T16:13:49.346", cal.getTime()); cal.set(Calendar.MILLISECOND, 340); checkLastModified("2014-02-12T16:13:49.34", cal.getTime()); cal.set(Calendar.MILLISECOND, 300); checkLastModified("2014-02-12T16:13:49.3", cal.getTime()); cal.set(Calendar.MILLISECOND, 0); checkLastModified("2014-02-12T16:13:49.", cal.getTime()); checkLastModified("2014-02-12T16:13:49", cal.getTime()); }
From source file:com.mtt.myapp.home.controller.HomeController.java
/** * Initialize {@link HomeController}.//w w w . j a v a 2 s .com */ @PostConstruct public void init() { timeZones = new ArrayList<TimeZone>(); final String[] timeZoneIds = TimeZone.getAvailableIDs(); for (final String id : timeZoneIds) { if (id.matches(TIMEZONE_ID_PREFIXES) && !TimeZone.getTimeZone(id).getDisplayName().contains("GMT")) { timeZones.add(TimeZone.getTimeZone(id)); } } Collections.sort(timeZones, new Comparator<TimeZone>() { public int compare(final TimeZone a, final TimeZone b) { return a.getID().compareTo(b.getID()); } }); scheduledTaskService.runAsync(new Runnable() { @Override public void run() { getLeftPanelEntries(); getRightPanelEntries(); } }); }
From source file:com.aerospike.load.Utils.java
/** * Parse command line parameters.//from ww w . j av a 2 s. c o m * @param cl Commandline arguments * @return Parameters * @throws Exception */ protected static Parameters parseParameters(CommandLine cl) { String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", null); String timeToLive = cl.getOptionValue("et", "-1"); int ttl = (Integer.parseInt(timeToLive)); String timeout = cl.getOptionValue("tt", "0"); int to = (Integer.parseInt(timeout)); //Get timezone offset //get user input for timeZone and check for valid ID if (cl.hasOption("T")) { if (!Utils.checkTimeZoneID(cl)) log.error("TimeZone given is not a valid ID"); } String timeZone = cl.getOptionValue("T", TimeZone.getDefault().getID()); TimeZone source = TimeZone.getTimeZone(timeZone); TimeZone local = TimeZone.getDefault(); long timeZoneOffset = local.getRawOffset() - source.getRawOffset(); String errorCount = cl.getOptionValue("ec", "0"); int abortErrorCount = Integer.parseInt(errorCount); String writeAction = cl.getOptionValue("wa", "UPDATE"); WritePolicy writePolicy = new WritePolicy(); writePolicy.recordExistsAction = RecordExistsAction.valueOf(writeAction.toUpperCase()); writePolicy.timeout = to; char delimiter = ','; boolean ignoreFirstLine = true; boolean verbose = false; if (cl.hasOption("v")) { verbose = true; } return new Parameters(host, port, namespace, set, ttl, Constants.CSV_FILE, delimiter, timeZoneOffset, ignoreFirstLine, verbose, abortErrorCount, writePolicy); }
From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBolt.java
void logDate(LogRecord record) { Date date = record.getDate(); if (date == null) { logger.error("Record date is null!"); } else {/*w w w .ja v a 2s. co m*/ SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); sdf.setTimeZone(TimeZone.getTimeZone(ZoneId.of("UTC"))); super.log(logger, sdf.format(date)); } }
From source file:DateUtils.java
public static final String getTimeFromDate(Date dt, String tzString) { try {/*from w w w .j a v a 2s . co m*/ GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }
From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java
/** * <pre>/*from ww w . j a v a2s . c o m*/ * YYYYMMDDHH24MISS? ?? ?? XMLGregorialCalendar ? GMT(GMT+09:00) ? . * </pre> * @param dateString * @return */ public static String convertFormattedStringToXmlGregorianCalendarStr(String dateString) { Assert.notNull(dateString, "dateString must not be null."); if (dateString.length() < 14) { dateString = StringUtils.rightPad(dateString, 14, '0'); } Assert.isTrue(dateString.length() == 14, "dateString's length must be 14."); GregorianCalendar cal = null; XMLGregorianCalendar calender = null; try { cal = convertTimezone(getDate(dateString), TimeZone.getTimeZone("ROK")); calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); return calender.toString(); } catch (Exception e) { throw new IllegalArgumentException( " . : [Date : " + dateString + " ]"); } }
From source file:com.jaspersoft.jasperserver.war.common.JdkTimeZonesList.java
protected TimeZone loadTimeZone(String id) { TimeZone timeZone = TimeZone.getTimeZone(id); if (timeZone == null) { String quotedTimezone = "\"" + id + "\""; throw new JSException("jsexception.unknown.timezone", new Object[] { quotedTimezone }); }//from w w w .j a v a2 s . c om return timeZone; }
From source file:net.sf.jasperreports.groups.keeptogether.KeepTogetherTest.java
@Test public void keepTogetherReports() throws JRException, NoSuchAlgorithmException, IOException { HashMap<String, Object> params = new HashMap<String, Object>(); params.put(JRParameter.REPORT_LOCALE, Locale.US); params.put(JRParameter.REPORT_TIME_ZONE, TimeZone.getTimeZone("GMT")); for (int i = 1; i <= 13; i++) { String jrxmlFileName = "net/sf/jasperreports/groups/keeptogether/repo/KeepTogetherReport." + i + ".jrxml"; JasperReport report = compileReport(jrxmlFileName); JasperPrint print = fillManager.fill(report, params); assert !print.getPages().isEmpty(); String xmlExportDigest = xmlExportDigest(print); log.debug("Plain report got " + xmlExportDigest); String referenceXmlExportDigest = getFileDigest( "net/sf/jasperreports/groups/keeptogether/repo/KeepTogetherReport." + i + ".reference.jrpxml"); assert xmlExportDigest.equals(referenceXmlExportDigest); }/*w w w .j a v a 2 s. c o m*/ }