List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:com.hbm.devices.scan.ui.android.DeviceZipper.java
static Uri saveAnnounces(@NonNull List<Announce> announces, @NonNull AppCompatActivity activity) { final TimeZone tz = TimeZone.getTimeZone("UTC"); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US); df.setTimeZone(tz); final String isoDate = df.format(new Date()); final Charset charSet = Charset.forName("UTF-8"); try {/*from w w w.java 2 s . co m*/ final File file = createFile(activity); if (file == null) { return null; } final FileOutputStream fos = new FileOutputStream(file, false); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); final ZipEntry entry = new ZipEntry("devices.json"); zos.putNextEntry(entry); zos.write(("{\"date\":\"" + isoDate + "\",").getBytes(charSet)); zos.write(("\"version\": \"1.0\",").getBytes(charSet)); zos.write("\"devices\":[".getBytes(charSet)); final Iterator<Announce> iterator = announces.iterator(); while (iterator.hasNext()) { final Announce announce = iterator.next(); zos.write(announce.getJSONString().getBytes(charSet)); if (iterator.hasNext()) { zos.write(",\n".getBytes(charSet)); } } zos.write("]}".getBytes(charSet)); zos.closeEntry(); zos.close(); fos.close(); return FileProvider.getUriForFile(activity, "com.hbm.devices.scan.ui.android.fileprovider", file); } catch (IOException e) { Toast.makeText(activity, activity.getString(R.string.could_not_create, e), Toast.LENGTH_SHORT).show(); return null; } }
From source file:org.wso2.ei.analytics.elk.publisher.ElasticStatisticsPublisher.java
/** * Takes time in milliseconds and returns the formatted date and time according to Elasticsearch * * @param time long time in millis// ww w. ja va 2s .com * @return timeStamp formatted according to the Elasticsearch */ private static String getFormattedDate(long time) { Date date = new Date(time); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String formattedDate = dateFormat.format(date); DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss.SSS"); timeFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); String formattedTime = timeFormat.format(date); return formattedDate + "T" + formattedTime + "Z"; }
From source file:com.gst.integrationtests.common.Utils.java
public static String convertDateToURLFormat(final Calendar dateToBeConvert) { DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy"); dateFormat.setTimeZone(Utils.getTimeZoneOfTenant()); return dateFormat.format(dateToBeConvert.getTime()); }
From source file:com.box.boxjavalibv2.utils.ISO8601DateParser.java
public static String toString(Date date) { DateFormat df = mThreadLocalSimpleDateFormat.get(); TimeZone tz = TimeZone.getTimeZone("UTC"); df.setTimeZone(tz); String output = df.format(date); String result = output.replaceAll("UTC", "+00:00"); return result; }
From source file:org.obm.caldav.server.reports.FilterParser.java
private static TimeRange getTimeRange(Element elem) { TimeRange tr = new TimeRange(); Element timeRange = DOMUtils.getUniqueElement(elem, "time-range", Filter.NAMESPACE); if (timeRange != null) { DateFormat df = new SimpleDateFormat(patternUTC); df.setTimeZone(TimeZone.getTimeZone("UTC")); String start = timeRange.getAttribute("start"); if (start != null && "".equals(start)) { try { Date dStart = df.parse(start); tr.setStart(dStart);// w w w. j a v a2 s . c om } catch (ParseException e) { logger.error(e.getMessage(), e); } } String end = timeRange.getAttribute("end"); if (end != null && "".equals(start)) { try { Date dEnd = df.parse(end); tr.setEnd(dEnd); } catch (ParseException e) { logger.error(e.getMessage(), e); } } } return tr; }
From source file:io.seldon.spark.actions.JobUtils.java
public static long utc_to_unixts(String utc_date) throws ParseException { DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); utcFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = utcFormat.parse(utc_date); return (date.getTime() / 1000); }
From source file:com.netflix.scheduledactions.Execution.java
private static DateFormat newDateFormat() { DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setTimeZone(TimeZone.getTimeZone(DATE_FORMAT_TIMEZONE)); return dateFormat; }
From source file:org.bimserver.plugins.web.AbstractWebModulePlugin.java
public static DateFormat expiresDateFormat() { DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return httpDateFormat; }
From source file:com.microsoft.aad.adal4j.WSTrustRequest.java
private static StringBuilder buildSecurityHeader(StringBuilder securityHeaderBuilder, String username, String password, WSTrustVersion version) { StringBuilder messageCredentialsBuilder = new StringBuilder(MAX_EXPECTED_MESSAGE_SIZE); String guid = UUID.randomUUID().toString(); username = StringEscapeUtils.escapeXml10(username); password = StringEscapeUtils.escapeXml10(password); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = new Date(); String currentTimeString = dateFormat.format(date); // Expiry is 10 minutes after creation int toAdd = 60 * 1000 * 10; date = new Date(date.getTime() + toAdd); String expiryTimeString = dateFormat.format(date); messageCredentialsBuilder.append(String.format("<o:UsernameToken u:Id='uuid-" + "%s'>" + // guid "<o:Username>%s</o:Username>" + // username "<o:Password>%s</o:Password>" + // password "</o:UsernameToken>", guid, username, password)); securityHeaderBuilder.append(//from w w w . java2 s.c o m "<o:Security s:mustUnderstand='1' xmlns:o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>"); securityHeaderBuilder.append(String.format("<u:Timestamp u:Id='_0'>" + "<u:Created>%s</u:Created>" + // created "<u:Expires>%s</u:Expires>" + // Expires "</u:Timestamp>", currentTimeString, expiryTimeString)); securityHeaderBuilder.append(messageCredentialsBuilder.toString()); securityHeaderBuilder.append("</o:Security>"); return securityHeaderBuilder; }
From source file:com.indoqa.lang.util.TimeUtils.java
private static DateFormat createDateFormat() { DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setTimeZone(TIME_ZONE); return dateFormat; }