List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:com.haulmont.chile.core.datatypes.impl.DateTimeDatatype.java
@Nullable @Override//from www .j av a 2s.co m public Date parse(@Nullable String value, Locale locale, TimeZone timeZone) throws ParseException { if (StringUtils.isBlank(value)) { return null; } FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateFormat format = new SimpleDateFormat(formatStrings.getDateTimeFormat()); if (timeZone != null) { format.setTimeZone(timeZone); } return format.parse(value.trim()); }
From source file:de.mpg.mpdl.inge.syndication.presentation.RestServlet.java
/** * {@inheritDoc}//from w ww. ja v a 2 s . co m */ @Override protected final void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String url = null; try { url = PropertyReader.getProperty("escidoc.syndication.service.url") + req.getServletPath() + req.getPathInfo(); } catch (Exception e) { handleException(e, resp); } String q = req.getQueryString(); if (Utils.checkVal(q)) { url += "?" + q; } Feed feed = synd.getFeeds().matchFeedByUri(url); // set correct mime-type resp.setContentType("application/" + (url.contains("rss_") ? "rss" : "atom") + "+xml; charset=utf-8"); // cache handling String ttl = feed.getCachingTtl(); if (Utils.checkVal(ttl)) { long ttlLong = Long.parseLong(ttl) * 1000L; resp.setHeader("control-cache", "max-age=" + ttl + ", must-revalidate"); DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); df.setTimeZone(TimeZone.getTimeZone("GMT")); resp.setHeader("Expires", df.format(new Date(System.currentTimeMillis() + ttlLong))); } try { synd.getFeed(url, resp.getWriter()); } catch (SyndicationException e) { handleException(e, resp); } catch (URISyntaxException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong URI syntax: " + url); return; } catch (FeedException e) { handleException(e, resp); } }
From source file:org.alfresco.rest.framework.jacksonextensions.JacksonHelper.java
@Override public void afterPropertiesSet() throws Exception { //Configure the objectMapper ready for use objectMapper = new ObjectMapper(); objectMapper.registerModule(module); objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY); //or NON_EMPTY? objectMapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false); objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); DateFormat DATE_FORMAT_ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); DATE_FORMAT_ISO8601.setTimeZone(TimeZone.getTimeZone("UTC")); objectMapper.setDateFormat(DATE_FORMAT_ISO8601); objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); }
From source file:org.infoscoop.web.GadgetResourceServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String reqUri = req.getRequestURI(); String resUri = reqUri.substring(reqUri.indexOf("/gadget/") + "/gadget/".length()); String type = resUri.substring(0, resUri.indexOf("/")); String typeUri = resUri.substring(type.length()); String path = typeUri.substring(0, typeUri.lastIndexOf("/") + 1); String name = typeUri.substring(path.length()); if (path.length() > 1 && path.charAt(path.length() - 1) == '/') path = path.substring(0, path.length() - 1); if (name.equals(type + ".xml") && "/".equals(path)) { resp.sendError(403);/*from w ww.j a v a2 s. com*/ return; } String ifModifiedSinceStr = req.getHeader("if-modified-since"); GadgetResourceService service = GadgetResourceService.getHandle(); Gadget gadget = service.getResource(type, path, name); if (gadget == null) { log.info("Gadget Resource: [" + type + "]@[" + path + "]/[" + name + "]" + " 404 Not Found"); resp.sendError(404); return; } DateFormat dateFormat = DateUtility.newGMTDateFormat(); // IE does not consider time zone dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT")); if (ifModifiedSinceStr != null) { try { long ifModifiedSince = dateFormat.parse(ifModifiedSinceStr).getTime(); // Delete millisecond Calendar c = Calendar.getInstance(); c.setTime(gadget.getLastmodified()); c.set(Calendar.MILLISECOND, 0); long lastModified = c.getTimeInMillis(); if (lastModified <= ifModifiedSince) { log.info("Gadget Resource: [" + type + "]@[" + path + "]/[" + name + "]" + " 302 Not Modified"); resp.sendError(304); return; } } catch (Exception e) { log.error("", e); } } log.info("Gadget Resource: [" + type + "]@[" + path + "]/[" + name + "]" + " 200 Success"); resp.setContentType(getServletContext().getMimeType(name)); if (gadget.getLastmodified() != null) resp.setHeader("Last-Modified", dateFormat.format(gadget.getLastmodified())); byte[] data = gadget.getData(); resp.setContentLength(data.length); resp.getOutputStream().write(data); resp.getOutputStream().flush(); }
From source file:org.openecomp.sdcrests.action.rest.services.ActionsImpl.java
/** * Convert timestamp to UTC format date string. * * @param timeStamp UTC timestamp to be converted to the UTC Date format. * @return UTC formatted Date string from timestamp. *//*from w ww . ja va 2 s . c om*/ public static String getUTCDateStringFromTimestamp(Date timeStamp) { DateFormat df = new SimpleDateFormat("dd MMM yyyy kk:mm:ss z"); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(timeStamp); }
From source file:com.balch.mocktrade.finance.QuoteYahooFinance.java
@Override public void setLastTradeTime(Date time) { DateFormat df = new SimpleDateFormat("M/d/yy h:mma", Locale.US); df.setTimeZone(TimeZone.getTimeZone("America/New_York")); String dateStr = df.format(time); String[] parts = dateStr.split(" "); this.data.put(LastTradeDate, parts[0]); this.data.put(LastTradeTime, parts[1]); }
From source file:com.balch.mocktrade.finance.QuoteYahooFinance.java
@Override public Date getLastTradeTime() { DateFormat df = new SimpleDateFormat("M/d/yy h:mma", Locale.US); df.setTimeZone(TimeZone.getTimeZone("America/New_York")); String dateStr = this.data.get(LastTradeDate) + " " + this.data.get(LastTradeTime).toUpperCase(); try {//from www . j a v a2s . c o m return df.parse(dateStr); } catch (ParseException e) { Log.e(TAG, "Error parsing date:" + dateStr, e); throw new RuntimeException(e); } }
From source file:de.mpg.escidoc.services.syndication.presentation.RestServlet.java
/** * {@inheritDoc}//from w ww.j a va 2s .c o m */ @Override protected final void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String url = null; try { url = PropertyReader.getProperty("escidoc.syndication.service.url") + req.getServletPath() + req.getPathInfo(); } catch (Exception e) { handleException(e, resp); } String q = req.getQueryString(); if (Utils.checkVal(q)) { url += "?" + q; } Feed feed = synd.getFeeds().matchFeedByUri(url); //set correct mime-type resp.setContentType("application/" + (url.contains("rss_") ? "rss" : "atom") + "+xml; charset=utf-8"); //cache handling String ttl = feed.getCachingTtl(); if (Utils.checkVal(ttl)) { long ttlLong = Long.parseLong(ttl) * 1000L; resp.setHeader("control-cache", "max-age=" + ttl + ", must-revalidate"); DateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); df.setTimeZone(TimeZone.getTimeZone("GMT")); resp.setHeader("Expires", df.format(new Date(System.currentTimeMillis() + ttlLong))); } try { synd.getFeed(url, resp.getWriter()); } catch (SyndicationException e) { handleException(e, resp); } catch (URISyntaxException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong URI syntax: " + url); return; } catch (FeedException e) { handleException(e, resp); } }
From source file:org.apache.synapse.mediators.deprecation.DeprecationMediator.java
private boolean isDeprecated(SynapseObject service) { try {//from w ww .j a va 2s . co m if (service.getBoolean("enabled").booleanValue()) { Calendar current = Calendar.getInstance(); TimeZone tz = current.getTimeZone(); int offset = tz.getRawOffset(); Calendar calendar = new GregorianCalendar(tz); DateFormat df = new SimpleDateFormat("d/M/y:H:m"); df.setTimeZone(tz); Date d1 = service.getDate(DeprecationConstants.CFG_DEPRECATION_FROM_DATE); Calendar fromCalendar = new GregorianCalendar(tz); d1.setTime(d1.getTime() + offset); fromCalendar.setTime(d1); String toDate = service.getDate(DeprecationConstants.CFG_DEPRECATION_TO_DATE).toString(); if (toDate == null || (toDate.length() == 0)) { return calendar.before(fromCalendar); } Date d2 = service.getDate("toDate"); Calendar toCalendar = new GregorianCalendar(tz); d2.setTime(d2.getTime() + offset); toCalendar.setTime(d2); return (calendar.after(fromCalendar) && calendar.before(toCalendar)); } } catch (Exception e) { e.printStackTrace(); return false; } return false; }
From source file:com.pingidentity.adapters.idp.mobileid.restservice.MssSignatureRequestJson.java
private String getInstant() { DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(TimeZone.getTimeZone("UTC")); return df.format(new Date()); }