List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:mixi4j.internal.util.z_M4JInternalParseUtil.java
public static Date getDate(String name, String format) throws MixiException { SimpleDateFormat sdf = formatMap.get().get(format); if (null == sdf) { sdf = new SimpleDateFormat(format, Locale.ENGLISH); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); formatMap.get().put(format, sdf); }/* w w w. j a v a 2s .co m*/ try { return sdf.parse(name); } catch (ParseException pe) { throw new MixiException("Unexpected date format(" + name + ") returned from twitter.com", pe); } }
From source file:ch.cern.db.flume.sink.elasticsearch.TimeBasedIndexNameBuilder.java
@Override public void configure(Context context) { String dateFormatString = context.getString(DATE_FORMAT); String timeZoneString = context.getString(TIME_ZONE); if (StringUtils.isBlank(dateFormatString)) { dateFormatString = DEFAULT_DATE_FORMAT; }// w w w.j av a2 s. co m if (StringUtils.isBlank(timeZoneString)) { timeZoneString = DEFAULT_TIME_ZONE; } fastDateFormat = FastDateFormat.getInstance(dateFormatString, TimeZone.getTimeZone(timeZoneString)); indexPrefix = context.getString(ElasticSearchSinkConstants.INDEX_NAME); }
From source file:org.codehaus.modello.generator.jackson.JacksonVerifier.java
/** * TODO: Add a association thats not under the root element *///from w ww .j a v a 2 s . c om public void verify() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); verifyWriter(); }
From source file:com.webpagebytes.cms.controllers.ArticleController.java
public void create(HttpServletRequest request, HttpServletResponse response, String requestUri) throws WPBException { try {/*from w w w. ja v a 2 s. co m*/ String jsonRequest = httpServletToolbox.getBodyText(request); WPBArticle article = (WPBArticle) jsonObjectConverter.objectFromJSONString(jsonRequest, WPBArticle.class); Map<String, String> errors = validator.validateCreate(article); if (errors.size() > 0) { httpServletToolbox.writeBodyResponseAsJson(response, "", errors); return; } article.setLastModified(Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime()); article.setExternalKey(adminStorage.getUniqueId()); WPBArticle newArticle = adminStorage.add(article); WPBResource resource = new WPBResource(newArticle.getExternalKey(), newArticle.getTitle(), WPBResource.ARTICLE_TYPE); try { adminStorage.addWithKey(resource); } catch (Exception e) { // do not propagate further } org.json.JSONObject returnJson = new org.json.JSONObject(); returnJson.put(DATA, jsonObjectConverter.JSONFromObject(newArticle)); httpServletToolbox.writeBodyResponseAsJson(response, returnJson, null); } catch (Exception e) { Map<String, String> errors = new HashMap<String, String>(); errors.put("", WPBErrors.WB_CANT_CREATE_RECORD); httpServletToolbox.writeBodyResponseAsJson(response, jsonObjectConverter.JSONObjectFromMap(null), errors); } }
From source file:ws.doerr.cssinliner.email.mandrill.MandrillEmailService.java
public MandrillEmailService() { formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); config = Configuration.get(MandrillConfig.class); Client client = ClientBuilder.newClient(); target = client.target(MANDRILL_URL); }
From source file:io.apiman.gateway.engine.jdbc.JdbcMetrics.java
/** * Process the next item in the queue./*from w ww. ja va 2 s .c o m*/ */ @SuppressWarnings("nls") protected void processQueue() { try { RequestMetric metric = queue.take(); QueryRunner run = new QueryRunner(ds); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.setTime(metric.getRequestStart()); long rstart = cal.getTimeInMillis(); long rend = metric.getRequestEnd().getTime(); long duration = metric.getRequestDuration(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); long minute = cal.getTimeInMillis(); cal.set(Calendar.MINUTE, 0); long hour = cal.getTimeInMillis(); cal.set(Calendar.HOUR_OF_DAY, 0); long day = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); long week = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); long month = cal.getTimeInMillis(); String api_org_id = metric.getApiOrgId(); String api_id = metric.getApiId(); String api_version = metric.getApiVersion(); String client_org_id = metric.getClientOrgId(); String client_id = metric.getClientId(); String client_version = metric.getClientVersion(); String plan = metric.getPlanId(); String user_id = metric.getUser(); String rtype = null; if (metric.isFailure()) { rtype = "failure"; } else if (metric.isError()) { rtype = "error"; } long bytes_up = metric.getBytesUploaded(); long bytes_down = metric.getBytesDownloaded(); // Now insert a row for the metric. run.update("INSERT INTO gw_requests (" + "rstart, rend, duration, month, week, day, hour, minute, " + "api_org_id, api_id, api_version, " + "client_org_id, client_id, client_version, plan, " + "user_id, resp_type, bytes_up, bytes_down) VALUES (" + "?, ?, ?, ?, ?, ?, ?, ?," + "?, ?, ?," + "?, ?, ?, ?," + "?, ?, ?, ?)", rstart, rend, duration, month, week, day, hour, minute, api_org_id, api_id, api_version, client_org_id, client_id, client_version, plan, user_id, rtype, bytes_up, bytes_down); } catch (InterruptedException ie) { // This means that the thread was stopped. } catch (Exception e) { // TODO better logging of this unlikely error System.err.println("Error adding metric to database:"); //$NON-NLS-1$ e.printStackTrace(); return; } }
From source file:DateUtil.java
/** * Parses the date value using the given date formats. * * @param dateValue the date value to parse * @param dateFormats the date formats to use * @param startDate During parsing, two digit years will be placed in the range * <code>startDate</code> to <code>startDate + 100 years</code>. This value may * be <code>null</code>. When <code>null</code> is given as a parameter, year * <code>2000</code> will be used. * @return the parsed date/* w w w. ja v a 2 s .c om*/ * @throws DateParseException if none of the dataFormats could parse the dateValue */ public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) { if (dateValue == null) { throw new IllegalArgumentException("dateValue is null"); } if (dateFormats == null) { dateFormats = DEFAULT_PATTERNS; } if (startDate == null) { startDate = DEFAULT_TWO_DIGIT_YEAR_START; } // trim single quotes around date if present // see issue #5279 if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) { dateValue = dateValue.substring(1, dateValue.length() - 1); } SimpleDateFormat dateParser = null; for (String format : dateFormats) { if (dateParser == null) { dateParser = new SimpleDateFormat(format, Locale.US); dateParser.setTimeZone(TimeZone.getTimeZone("GMT")); dateParser.set2DigitYearStart(startDate); } else { dateParser.applyPattern(format); } try { return dateParser.parse(dateValue); } catch (ParseException pe) { // ignore this exception, we will try the next format } } // we were unable to parse the date throw new RuntimeException("Unable to parse the date " + dateValue); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.message.MMXPubSubItem.java
private void parsePayload(Element payloadElement) { if (payloadElement != null) { Document d = payloadElement.getDocument(); Node mmxPayloadNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_PAYLOAD)); if (mmxPayloadNode != null) { String mtype = mmxPayloadNode.valueOf("@mtype"); String stamp = DateFormatUtils.format(new DateTime(mmxPayloadNode.valueOf("@stamp")).toDate(), "yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC")); String data = mmxPayloadNode.getText(); payload = new MMXPubSubPayload(mtype, stamp, data); }//from w w w . j ava2 s. com Node mmxMetaNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_META)); if (mmxMetaNode != null) { meta = getMapFromJsonString(mmxMetaNode.getText()); } } }
From source file:lydichris.smashbracket.controllers.TournamentController.java
@RequestMapping(value = "/tournaments", method = RequestMethod.POST) Tournament createTournament(@RequestParam String name, @RequestParam String description, @RequestParam(value = "maxEntrants", required = false, defaultValue = "0") int maxEntrants, @RequestParam String game, @RequestParam TournamentType tournamentType, @RequestParam String startTime, @RequestParam String hostId) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:m:s zzz", Locale.US); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); Date startTimeDate = formatter.parse(startTime); //Should take in userName for host somehow //Consider adding location return tournamentService.createTournament(name, description, maxEntrants, game, tournamentType, startTimeDate, hostId);// ww w . j av a2s. c o m }
From source file:net.pms.network.UPNPHelper.java
/** * Send UPnP discovery search message to discover devices of interest on * the network.//from w w w . jav a 2 s . co m * * @param host The multicast channel * @param port The multicast port * @param st The search target string * @throws IOException Signals that an I/O exception has occurred. */ private static void sendDiscover(String host, int port, String st) throws IOException { String usn = PMS.get().usn(); String serverHost = PMS.get().getServer().getHost(); int serverPort = PMS.get().getServer().getPort(); SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); if (st.equals(usn)) { usn = ""; } else { usn += "::"; } StringBuilder discovery = new StringBuilder(); discovery.append("HTTP/1.1 200 OK").append(CRLF); discovery.append("CACHE-CONTROL: max-age=1200").append(CRLF); discovery.append("DATE: ").append(sdf.format(new Date(System.currentTimeMillis()))).append(" GMT") .append(CRLF); discovery.append("LOCATION: http://").append(serverHost).append(":").append(serverPort) .append("/description/fetch").append(CRLF); discovery.append("SERVER: ").append(PMS.get().getServerName()).append(CRLF); discovery.append("ST: ").append(st).append(CRLF); discovery.append("EXT: ").append(CRLF); discovery.append("USN: ").append(usn).append(st).append(CRLF); discovery.append("Content-Length: 0").append(CRLF).append(CRLF); sendReply(host, port, discovery.toString()); }