List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:org.apache.ivory.retention.FeedEvictor.java
private Date getDate(Path file, String inMask, String dateMask, String timeZone) { String path = extractDatePartFromPathMask(inMask, file.toString()); populateDatePartMap(path, dateMask); String errArg = file + "(" + inMask + ")"; if (map.isEmpty()) { LOG.warn("No date present in " + errArg); return null; }//from w w w .ja v a 2 s . c o m String date = ""; int ordinal = 0; for (VARS var : map.keySet()) { if (ordinal++ == var.ordinal()) { date += map.get(var); } else { LOG.warn("Prior element to " + var + " is missing " + errArg); return null; } } try { DateFormat dateFormat = new SimpleDateFormat(format.substring(0, date.length())); dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone)); return dateFormat.parse(date); } catch (ParseException e) { LOG.warn("Unable to parse date : " + date + ", " + errArg); return null; } }
From source file:eu.payzen.webservices.sdk.handler.soap.HeaderHandler.java
/** * Takes the outgoing SOAP message and modifies it adding the header * information//from www.j a v a 2 s .co m * * @param smc SOAP message context * @return boolean indicating outbound property */ public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (Boolean.TRUE.equals(outboundProperty)) { SOAPMessage message = smc.getMessage(); try { SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); //Creates header into SOAP envelope SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } // Add shopId addHeaderField(header, "shopId", this.shopId); // Add User name if (wsUser != null) { addHeaderField(header, "wsUser", this.wsUser); } // Add return url if (returnUrl != null) { addHeaderField(header, "returnUrl", this.returnUrl); } // Add ecsPaymentId if (ecsPaymentId != null) { addHeaderField(header, "ecsPaymentId", this.ecsPaymentId); } // Add remoteId if (remoteId != null) { addHeaderField(header, "remoteId", this.remoteId); } //DynamicHeaders if (dynamicHeaders != null) { for (String key : dynamicHeaders.keySet()) { String value = dynamicHeaders.get(key); if (value != null) { addHeaderField(header, key, value); } } } // Timestamp TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date()); addHeaderField(header, "timestamp", nowAsISO); // Mode addHeaderField(header, "mode", this.mode); // Add requestId String requestId = UUID.randomUUID().toString(); addHeaderField(header, "requestId", requestId); // Authentication token String tokenString = requestId + nowAsISO; addHeaderField(header, "authToken", sign(tokenString, shopKey)); } catch (SOAPException e) { logger.error("Error sending header", e); } } return outboundProperty; }
From source file:admin.java
private String getGMT7(Date date) { DateFormat gmtFormat = new SimpleDateFormat(); TimeZone gmtTime = TimeZone.getTimeZone("GMT+7"); gmtFormat.setTimeZone(gmtTime); return date.toString(); }
From source file:com.zns.comicdroid.amazon.SignedRequestsHelper.java
/** * Generate a ISO-8601 format timestamp as required by Amazon. * //from w w w.ja va 2s . com * @return ISO-8601 format timestamp. */ @SuppressLint("SimpleDateFormat") private String timestamp() { String timestamp = null; Calendar cal = Calendar.getInstance(); DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); dfm.setTimeZone(TimeZone.getTimeZone("GMT")); timestamp = dfm.format(cal.getTime()); return timestamp; }
From source file:org.apache.nifi.csv.TestWriteCSVResult.java
private DateFormat getDateFormat(final String format) { final DateFormat df = new SimpleDateFormat(format); df.setTimeZone(TimeZone.getTimeZone("gmt")); return df;//from www .j av a 2 s. co m }
From source file:de.schildbach.wallet.ui.BackupWalletDialogFragment.java
private File determineBackupFile() { Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.mkdirs(); checkState(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.isDirectory(), "%s is not a directory", Constants.Files.EXTERNAL_WALLET_BACKUP_DIR); final DateFormat dateFormat = Iso8601Format.newDateFormat(); dateFormat.setTimeZone(TimeZone.getDefault()); for (int i = 0; true; i++) { final StringBuilder filename = new StringBuilder(Constants.Files.EXTERNAL_WALLET_BACKUP); filename.append('-'); filename.append(dateFormat.format(new Date())); if (i > 0) filename.append(" (").append(i).append(')'); final File file = new File(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR, filename.toString()); if (!file.exists()) return file; }//from ww w.ja va 2s. c om }
From source file:com.edgenius.wiki.ext.calendar.web.CalendarAction.java
/** * @return//from w ww . ja v a 2s. co m */ private DateFormat getDateFormat() { TimeZone tz = TimeZoneUtil.guessTimeZone(timezone); DateFormat format = new SimpleDateFormat(CAL_DATEFORMAT); format.setTimeZone(tz); return format; }
From source file:org.esupportail.pay.services.PayBoxService.java
protected String getCurrentTime() { TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String nowAsISO = df.format(new Date()); return nowAsISO; }
From source file:net.bashtech.geobot.JSONUtil.java
public static boolean krakenOutdatedChannel(String channel) { if (BotManager.getInstance().twitchChannels == false) return false; try {// w w w .j a v a2 s . com JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContentTwitch("https://api.twitch.tv/kraken/channels/" + channel, 2)); JSONObject jsonObject = (JSONObject) obj; Object statusO = jsonObject.get("status"); Long status; if (statusO != null) { status = (Long) statusO; if (status == 422 || status == 404) { System.out.println("Channel " + channel + " returned status: " + status + ". Parting channel."); return true; } } String updatedAtString = (String) jsonObject.get("updated_at"); DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(java.util.TimeZone.getTimeZone("US/Pacific")); long differenceDay = 0; try { Date then = format.parse(updatedAtString); long differenceSec = (long) (System.currentTimeMillis() / 1000) - (then.getTime() / 1000); differenceDay = (long) (differenceSec / 86400); } catch (Exception exi) { exi.printStackTrace(); } if (differenceDay > 30) { System.out.println( "Channel " + channel + " not updated in " + differenceDay + " days. Parting channel."); return true; } } catch (Exception ex) { return false; } return false; }
From source file:markson.visuals.sitapp.eventActivity.java
public void addtocal() throws ParseException { String location = null;/*from w ww . j av a 2 s.c o m*/ DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US); formatter.setTimeZone(TimeZone.getTimeZone("America/New_York")); Date StartTime = formatter.parse(date); Log.e("n", String.valueOf(StartTime.getTime())); Intent calint = new Intent(Intent.ACTION_INSERT); calint.setType("vnd.android.cursor.item/event"); calint.putExtra("title", name); calint.putExtra("description", description); calint.putExtra("beginTime", StartTime.getTime()); //calint.putExtra(Events.EVENT_TIMEZONE, "America/New_York"); if (description.contains("at")) { location = description.substring(description.lastIndexOf("at") + 3, description.length()); calint.putExtra("eventLocation", location); } startActivity(calint); }