List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:squash.booking.lambdas.core.RuleManager.java
private DayOfWeek dayOfWeekFromDate(String date) throws ParseException { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); formatter.setTimeZone(TimeZone.getTimeZone("Europe/London")); return formatter.parse(date).toInstant().atZone(TimeZone.getTimeZone("Europe/London").toZoneId()) .toLocalDate().getDayOfWeek(); }
From source file:de.interactive_instruments.ShapeChange.Target.EA.UmlModel.java
public void initialise(PackageInfo p, Model m, Options o, ShapeChangeResult r, boolean diagOnly) throws ShapeChangeAbortException { pi = p;/*www. ja v a2s . c o m*/ model = m; options = o; result = r; if (!initialised) { initialised = true; String outputDirectory = options.parameter(this.getClass().getName(), PARAM_OUTPUT_DIR); if (outputDirectory == null) outputDirectory = options.parameter("outputDirectory"); if (outputDirectory == null) outputDirectory = "."; outputFilename = options.parameter(this.getClass().getName(), "modelFilename"); if (outputFilename == null) outputFilename = "ShapeChangeExport.eap"; // change the default documentation template? documentationTemplate = options.parameter(this.getClass().getName(), "documentationTemplate"); documentationNoValue = options.parameter(this.getClass().getName(), "documentationNoValue"); /** Make sure repository file exists */ java.io.File repfile = null; java.io.File outDir = new java.io.File(outputDirectory); if (!outDir.exists()) { try { FileUtils.forceMkdir(outDir); } catch (IOException e) { String errormsg = e.getMessage(); r.addError(null, 32, errormsg, outputDirectory); return; } } repfile = new java.io.File(outDir, outputFilename); boolean ex = true; rep = new Repository(); if (!repfile.exists()) { ex = false; if (!outputFilename.toLowerCase().endsWith(".eap")) { outputFilename += ".eap"; repfile = new java.io.File(outputFilename); ex = repfile.exists(); } } String absname = repfile.getAbsolutePath(); if (!ex) { if (!rep.CreateModel(CreateModelType.cmEAPFromBase, absname, 0)) { r.addError(null, 31, absname); rep = null; return; } } /** Connect to EA Repository */ if (!rep.OpenFile(absname)) { String errormsg = rep.GetLastError(); r.addError(null, 30, errormsg, outputFilename); rep = null; return; } rep.RefreshModelView(0); Collection<Package> c = rep.GetModels(); Package root = c.GetAt((short) 0); TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); df.setTimeZone(tz); Package pOut = root.GetPackages().AddNew("ShapeChangeOutput-" + df.format(new Date()), "Class View"); if (!pOut.Update()) { result.addError("EA-Fehler: " + pOut.GetLastError()); } pOut_EaPkgId = pOut.GetPackageID(); } if (rep == null || pOut_EaPkgId == null) return; // repository not initialised // export app schema package clonePackage(pi, pOut_EaPkgId); }
From source file:org.sleuthkit.autopsy.casemodule.Case.java
/** * Convert the Java timezone ID to the "formatted" string that can be * accepted by the C/C++ code. Example: "America/New_York" converted to * "EST5EDT", etc//from ww w. j a v a 2s.co m * * @param timezoneID * * @return */ public static String convertTimeZone(String timezoneID) { TimeZone zone = TimeZone.getTimeZone(timezoneID); int offset = zone.getRawOffset() / 1000; int hour = offset / 3600; int min = (offset % 3600) / 60; DateFormat dfm = new SimpleDateFormat("z"); dfm.setTimeZone(zone); boolean hasDaylight = zone.useDaylightTime(); String first = dfm.format(new GregorianCalendar(2010, 1, 1).getTime()).substring(0, 3); // make it only 3 letters code String second = dfm.format(new GregorianCalendar(2011, 6, 6).getTime()).substring(0, 3); // make it only 3 letters code int mid = hour * -1; String result = first + Integer.toString(mid); if (min != 0) { result = result + ":" + Integer.toString(min); } if (hasDaylight) { result = result + second; } return result; }
From source file:org.dasein.cloud.virtustream.VirtustreamMethod.java
private String getSignature(String location, String apiKey, String accessKey, String version) throws UnsupportedEncodingException, SignatureException, CloudException, InternalException { Logger logger = Virtustream.getLogger(VirtustreamMethod.class); if (logger.isTraceEnabled()) { logger.trace("enter - " + VirtustreamMethod.class.getName() + ".getSignature(" + location + "," + apiKey + "," + accessKey + "," + version); }/*from w w w . j a v a 2 s . co m*/ try { Base64 obj = new Base64(); String key = apiKey; String secret = accessKey; 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()); String b64HashedSecret = new String(obj.encode(calculateHmac(secret, secret))); String bodyString = String.format("Location=%s&PublicKey=%s&UTCTimeStamp=%s&Version=1.0", "US1", key, URLEncoder.encode(nowAsISO, "UTF-8")); String clear = key + nowAsISO + bodyString + b64HashedSecret; String b64Clear = new String(obj.encode(clear.getBytes("UTF-8"))); String b64HashedSignature = new String(obj.encode(calculateHmac(clear, accessKey))); String doubleEncSig = new String(obj.encode(b64HashedSignature.getBytes("UTF-8"))); String b64Key = new String(obj.encode(key.getBytes("UTF-8"))); String auth = new String( obj.encode(String.format("%s:%s:%s", b64Key, doubleEncSig, b64Clear).getBytes("UTF-8"))); return auth; } finally { if (logger.isTraceEnabled()) { logger.trace("exit - " + VirtustreamMethod.class.getName() + ".getSignature()"); } } }
From source file:net.sourceforge.vulcan.core.support.AbstractProjectDomBuilder.java
private void addElapsedTime(Element root, ProjectStatusDto status, Locale locale) { final Date startDate = status.getStartDate(); if (startDate == null) { return;/*from w w w. j av a2 s . c om*/ } Date completionDate = status.getCompletionDate(); if (completionDate == null) { completionDate = new Date(); } final long elapsedMillis = completionDate.getTime() - startDate.getTime(); final Element elapsed = new Element("elapsed-time"); elapsed.setAttribute("millis", Long.toString(elapsedMillis)); final DateFormat format = new SimpleDateFormat(formatMessage("build.time.elapsed.format", null, locale), locale); format.setTimeZone(GMT_TIMEZONE); elapsed.setText(format.format(elapsedMillis)); root.addContent(elapsed); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java
@Override public StreamingOutput getAssignmentStream(Experiment.ID experimentID, Context context, Parameters parameters, Boolean ignoreNullBucket) { final List<Date> dateHours = getDateHourRangeList(experimentID, parameters); final String header = "experiment_id\tuser_id\tcontext\tbucket_label\tcreated\t" + System.getProperty("line.separator"); final DateFormat formatter = new SimpleDateFormat(defaultTimeFormat); formatter.setTimeZone(parameters.getTimeZone()); final StringBuilder sb = new StringBuilder(); return (os) -> { try (Writer writer = new BufferedWriter(new OutputStreamWriter(os, Charset.forName("UTF-8")))) { writer.write(header);/*ww w . j a v a2 s. c o m*/ for (Date dateHour : dateHours) { Result<UserAssignmentExport> result; LOGGER.debug("Query user assignment export for experimentID={}, at dateHour={}", experimentID.getRawID(), dateHour); if (ignoreNullBucket) { result = userAssignmentExportAccessor.selectBy(experimentID.getRawID(), dateHour, context.getContext(), false); } else { result = userAssignmentExportAccessor.selectBy(experimentID.getRawID(), dateHour, context.getContext()); } for (UserAssignmentExport userAssignmentExport : result) { sb.append(userAssignmentExport.getExperimentId()).append("\t") .append(userAssignmentExport.getUserId()).append("\t") .append(userAssignmentExport.getContext()).append("\t") .append(userAssignmentExport.getBucketLabel()).append("\t") .append(formatter.format(userAssignmentExport.getCreated())) .append(System.getProperty("line.separator")); writer.write(sb.toString()); sb.setLength(0); } } } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException( "Could not retrieve assignment for " + "experimentID = \"" + experimentID, e); } catch (IllegalArgumentException | IOException e) { throw new RepositoryException( "Could not write assignment to stream for " + "experimentID = \"" + experimentID, e); } }; }
From source file:net.sourceforge.vulcan.core.support.AbstractProjectDomBuilder.java
public Document createProjectSummaries(List<ProjectStatusDto> outcomes, Object fromLabel, Object toLabel, Locale locale) {// www . java 2 s.co m if (locale == null) { locale = Locale.getDefault(); } final DateFormat format = new SimpleDateFormat(formatMessage("build.timestamp.format", null, locale), locale); format.setTimeZone(SYSTEM_TIMEZONE); final Element root = new Element("build-history"); final Document doc = new Document(root); if (fromLabel instanceof java.util.Date) { fromLabel = format.format(fromLabel); } if (toLabel instanceof java.util.Date) { toLabel = format.format(toLabel); } root.setAttribute("from", fromLabel.toString()); root.setAttribute("to", toLabel.toString()); addXAxis(root, outcomes, format, locale); for (ProjectStatusDto outcome : outcomes) { final Element summary = new Element("project"); addBasicContents(summary, outcome, locale, format); addMetrics(summary, outcome.getMetrics(), locale); root.addContent(summary); } return doc; }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapter.java
public Date parseCoTDate(String dateString) throws Exception { if (!dateString.isEmpty()) { DateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); formatter1.setTimeZone(TimeZone.getTimeZone("Zulu")); DateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); formatter2.setTimeZone(TimeZone.getTimeZone("Zulu")); Date date = null;//from ww w. jav a2s . c om try { if (date == null) date = (Date) formatter1.parse(dateString); } catch (ParseException ex) { } try { if (date == null) date = (Date) formatter2.parse(dateString); } catch (ParseException ex) { } return date; } return null; }
From source file:com.examples.with.different.packagename.testcarver.DateTimeConverter.java
/** * Return a <code>DateFormat<code> for the Locale. * @param locale The Locale to create the Format with (may be null) * @param timeZone The Time Zone create the Format with (may be null) * * @return A Date Format.// w w w .j a v a 2 s . c om */ protected DateFormat getFormat(Locale locale, TimeZone timeZone) { DateFormat format = null; if (locale == null) { format = DateFormat.getDateInstance(DateFormat.SHORT); } else { format = DateFormat.getDateInstance(DateFormat.SHORT, locale); } if (timeZone != null) { format.setTimeZone(timeZone); } return format; }
From source file:net.sourceforge.vulcan.core.support.AbstractProjectDomBuilder.java
public final Document createProjectDocument(ProjectStatusDto status, Locale locale) { if (locale == null) { locale = Locale.getDefault(); }// w w w .j a va 2s.c o m final DateFormat format = new SimpleDateFormat(formatMessage("build.timestamp.format", null, locale), locale); format.setTimeZone(SYSTEM_TIMEZONE); final Element root = new Element("project"); final Document doc = new Document(root); addBasicContents(root, status, locale, format); final String repositoryUrl = status.getRepositoryUrl(); if (!StringUtils.isBlank(repositoryUrl)) { addChildNodeWithText(root, "repository-url", repositoryUrl); } if (status.getEstimatedBuildTimeMillis() != null) { addChildNodeWithText(root, "estimated-build-time", status.getEstimatedBuildTimeMillis().toString()); } addDependencies(root, status, format); addChangeLog(root, status, format); addBuildMessages(root, "error", status.getErrors()); addBuildMessages(root, "warning", status.getWarnings()); final Status buildStatus = status.getStatus(); if (buildStatus == null || !Status.PASS.equals(buildStatus)) { if (status.getLastGoodBuildNumber() != null) { addChildNodeWithText(root, "last-good-build-number", status.getLastGoodBuildNumber().toString()); } } final RevisionTokenDto lastKnownRevision = status.getLastKnownRevision(); if (status.getRevision() == null && lastKnownRevision != null) { final Element rev = addChildNodeWithText(root, "last-known-revision", lastKnownRevision.getLabel()); rev.setAttribute("numeric", lastKnownRevision.getRevision().toString()); } addMetrics(root, status.getMetrics(), locale); addTestFailures(root, status.getTestFailures()); final String workDir = status.getWorkDir(); if (isNotBlank(workDir)) { addReports(root, workDir); } return doc; }