List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:com.amazon.pay.impl.Util.java
public static String getTimestamp() { final Date date = new Date(); final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz"; final SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT); final TimeZone utc = TimeZone.getTimeZone("UTC"); sdf.setTimeZone(utc); String timeStamp = sdf.format(date); return timeStamp.replace("UTC", "Z"); }
From source file:com.predic8.membrane.core.util.HttpUtil.java
public static DateFormat createGMTDateFormat() { SimpleDateFormat GMT_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); GMT_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); return GMT_DATE_FORMAT; }
From source file:org.emfjson.jackson.module.EMFModule.java
/** * Returns a pre configured mapper with the EMF module. * * @return mapper/*from w w w . j a v a 2s .c o m*/ */ public static ObjectMapper setupDefaultMapper() { final ObjectMapper mapper = new ObjectMapper(); // same as emf final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); dateFormat.setTimeZone(TimeZone.getDefault()); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.setDateFormat(dateFormat); mapper.setTimeZone(TimeZone.getDefault()); mapper.registerModule(new EMFModule()); return mapper; }
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); }//from w w w. ja va2 s . c om try { return sdf.parse(name); } catch (ParseException pe) { throw new MixiException("Unexpected date format(" + name + ") returned from twitter.com", pe); } }
From source file:com.streamsets.pipeline.stage.bigquery.destination.BigQueryTarget.java
static SimpleDateFormat createSimpleDateFormat(String pattern) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat; }
From source file:com.kylinolap.dict.DateStrDictionary.java
static SimpleDateFormat getDateFormat(String datePattern) { ThreadLocal<SimpleDateFormat> formatThreadLocal = threadLocalMap.get(datePattern); if (formatThreadLocal == null) { threadLocalMap.put(datePattern, formatThreadLocal = new ThreadLocal<SimpleDateFormat>()); }/*from ww w . j a v a 2 s .co m*/ SimpleDateFormat format = formatThreadLocal.get(); if (format == null) { format = new SimpleDateFormat(datePattern); format.setTimeZone(TimeZone.getTimeZone("GMT")); // NOTE: this must // be GMT to // calculate // epoch date // correctly formatThreadLocal.set(format); } return format; }
From source file:com.zimbra.cs.service.account.GetAccountInfo.java
static void addUrls(Element response, Account account) throws ServiceException { Provisioning prov = Provisioning.getInstance(); Server server = prov.getServer(account); String hostname = server.getAttr(Provisioning.A_zimbraServiceHostname); Domain domain = prov.getDomain(account); if (server != null && hostname != null) { String httpSoap = URLUtil.getSoapPublicURL(server, domain, false); String httpsSoap = URLUtil.getSoapPublicURL(server, domain, true); if (httpSoap != null) { response.addAttribute(AccountConstants.E_SOAP_URL /* soapURL */, httpSoap, Element.Disposition.CONTENT); }/*from w w w . ja v a 2 s . c o m*/ if (httpsSoap != null && !httpsSoap.equalsIgnoreCase(httpSoap)) { /* Note: addAttribute with Element.Disposition.CONTENT REPLACEs any previous attribute with the same name. * i.e. Will NOT end up with both httpSoap and httpsSoap as values for "soapURL" */ response.addAttribute(AccountConstants.E_SOAP_URL /* soapURL */, httpsSoap, Element.Disposition.CONTENT); } String pubUrl = URLUtil.getPublicURLForDomain(server, domain, "", true); if (pubUrl != null) { response.addAttribute(AccountConstants.E_PUBLIC_URL, pubUrl, Element.Disposition.CONTENT); } if (AccessManager.getInstance().isAdequateAdminAccount(account)) { String publicAdminUrl = URLUtil.getPublicAdminConsoleURLForDomain(server, domain); if (publicAdminUrl != null) { response.addAttribute(AccountConstants.E_ADMIN_URL, publicAdminUrl, Element.Disposition.CONTENT); } } String changePasswordUrl = null; if (domain != null) { changePasswordUrl = domain.getAttr(Provisioning.A_zimbraChangePasswordURL); } if (changePasswordUrl != null) { response.addAttribute(AccountConstants.E_CHANGE_PASSWORD_URL, changePasswordUrl, Element.Disposition.CONTENT); } } //add a Community redirect URL if (account.getBooleanAttr(Provisioning.A_zimbraFeatureSocialExternalEnabled, false)) { String clientID = account.getAttr(Provisioning.A_zimbraCommunityAPIClientID); if (clientID == null) { ZimbraLog.account.debug( "Zimbra Community client ID is not properly configured. zimbraCommunityAPIClientID cannot be empty."); } String clientSecret = account.getAttr(Provisioning.A_zimbraCommunityAPIClientSecret); if (clientSecret == null) { ZimbraLog.account.debug( "Zimbra Community client secret is not properly configured. zimbraCommunityAPIClientSecret cannot be empty."); } String nameAttribute = account.getAttr(Provisioning.A_zimbraCommunityUsernameMapping); if (nameAttribute == null) { ZimbraLog.account.debug( "Zimbra Community name mapping is not properly configured. zimbraCommunityUsernameMapping cannot be empty"); } String socialBaseURL = account.getAttr(Provisioning.A_zimbraCommunityBaseURL); if (socialBaseURL == null) { ZimbraLog.account.debug( "Zimbra Community base URL is not properly configured. zimbraCommunityBaseURL cannot be empty"); } else { if (socialBaseURL.endsWith("/")) { //avoid double slashes socialBaseURL = socialBaseURL.substring(0, socialBaseURL.length() - 1); } } String socialTabURL = account.getAttr(Provisioning.A_zimbraCommunityHomeURL); if (socialTabURL == null) { ZimbraLog.account.debug( "Zimbra Community home URL is not properly configured. zimbraCommunityHomeURL cannot be empty"); } else { if (!socialTabURL.startsWith("/")) { //make sure the path is relative socialTabURL = "/".concat(socialTabURL); } } if (clientID != null && clientSecret != null && nameAttribute != null && socialBaseURL != null && socialTabURL != null) { try { Date today = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); Mac mac = Mac.getInstance("HmacSHA256"); SecretKeySpec key = new SecretKeySpec(clientSecret.getBytes("UTF8"), "HmacSHA256"); mac.init(key); byte[] rawHmac = mac.doFinal(String.format("%s%s%s%s", account.getUid(), formatter.format(today), socialBaseURL, socialTabURL).getBytes("UTF8")); String Base64Signature = Base64.encodeBase64String(rawHmac); String szURL = String.format( "%s/api.ashx/v2/oauth/redirect?client_id=%s&username=%s&time_stamp=%s&redirect_uri=%s&signature=%s", socialBaseURL, URLEncoder.encode(clientID, "UTF8"), account.getAttr(nameAttribute), URLEncoder.encode(formatter.format(today), "UTF8"), URLEncoder.encode(socialBaseURL.concat(socialTabURL), "UTF8"), URLEncoder.encode(Base64Signature, "UTF8")); response.addAttribute(AccountConstants.E_COMMUNITY_URL, szURL, Element.Disposition.CONTENT); } catch (UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException e) { throw ServiceException.FAILURE("Failed to generate community URL", e); } } } //add BOSH URL if Chat is enabled if (account.getBooleanAttr(Provisioning.A_zimbraFeatureChatEnabled, false)) { response.addAttribute(AccountConstants.E_BOSH_URL, server.getReverseProxyXmppBoshLocalHttpBindURL()); } }
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// ww w.j a v a2s .c o m * @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.hurence.logisland.utils.DateUtils.java
/** * Formats a date at any given format String, at any given Timezone String. * * * @param date Valid Date object/* w w w . j ava 2 s . co m*/ * @param format String representation of the format, e.g. "yyyy-MM-dd HH:mm" * @param timezone String representation of the time zone, e.g. "CST" * @return The formatted date in the given time zone. */ public static String toString(final Date date, final String format, final String timezone) { final TimeZone tz = TimeZone.getTimeZone(timezone); final SimpleDateFormat formatter = new SimpleDateFormat(format); formatter.setTimeZone(tz); return formatter.format(date); }
From source file:com.predic8.membrane.core.interceptor.cache.CacheInterceptor.java
static String toRFC(long timestamp) { SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format(new Date(timestamp)); }