List of usage examples for java.text DateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java
static Date parseDate(String dateString, String affixToTryOnYearOnly) { try {/* w w w .j a v a2 s .c o m*/ if (dateString.length() == 4 && dateString.matches("\\d\\d\\d\\d")) { dateString += affixToTryOnYearOnly; } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); if (StringUtils.isEmpty(dateString)) { return null; } return dateFormat.parse(dateString); } catch (Exception e) { System.out.println(e.getMessage()); return null; } }
From source file:com.kku.apps.pricesearch.util.SignedHelper.java
private static String timestamp() { String timestamp = null;/* ww w . j av a 2s . com*/ 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.hawkular.client.test.metrics.openshift.OpenshiftCollectionHistTest.java
/** * Save histogram data to file in csv format * @param filename file name with csv extension * @param histogram//from w w w . java2 s . c om * @param printToStdout set to true to also log the output in TestNG Reporter standard out */ public static void printHist(String filename, Map<Long, Integer> histogram, boolean printToStdout) { DateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("America/New_York")); PrintStream out = null; try { out = new PrintStream(new FileOutputStream(filename + ".csv")); for (Map.Entry<Long, Integer> e : histogram.entrySet()) { Date date = new Date(e.getKey()); String s = format.format(date) + "," + e.getValue(); out.println(s); if (printToStdout) { Reporter.log(s, true); } } } catch (Exception e) { Assert.fail("File IO error", e); } finally { IOUtils.closeQuietly(out); } }
From source file:lucee.runtime.converter.JSONDateFormat.java
public synchronized static String format(Date date, TimeZone tz) { tz = ThreadLocalPageContext.getTimeZone(tz); String id = locale.hashCode() + "-" + tz.getID(); DateFormat format = (DateFormat) map.get(id); if (format == null) { format = new SimpleDateFormat("MMMM, dd yyyy HH:mm:ss Z", locale); format.setTimeZone(tz); map.put(id, format);//from www .jav a 2s.co m } return format.format(date); }
From source file:org.seasar.mayaa.impl.util.DateFormatPool.java
public static DateFormat borrowRFC1123Format() { DateFormat result = borrowFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.ENGLISH); result.setTimeZone(TimeZone.getTimeZone("GMT")); return result; }
From source file:org.seasar.mayaa.impl.util.DateFormatPool.java
public static DateFormat borrowRFC2822Format() { DateFormat result = borrowFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH); result.setTimeZone(TimeZone.getTimeZone("GMT")); return result; }
From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java
public static String formatSince(String value, TimeZone timezone) { try {//from w ww .j a va 2s .c o m Date date = parse(value); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL); if (timezone != null) { formatter.setTimeZone(timezone); } return formatter.format(date); } catch (ParseException e) { OpenShiftCommonUIActivator.getDefault().getLogger() .logWarning("Unable to parse format duration value: " + value, e); } return value; }
From source file:gov.wa.wsdot.cms.utils.Migration.java
/** * Calculate number of days since the 1900 epoch. * //from w w w.j a v a 2 s.c o m * @param daysSinceEpoch days since epoch in milliseconds * @return converted date in the form "Tue Apr 09 07:56:37 PDT 2013" */ public static String convertDays(double daysSinceEpoch) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); // Set TimeZone to UTC Calendar startDate = Calendar.getInstance(); startDate.set(1899, 11, 31, 16, 0, 0); long MILLIS_PER_DAY = 86400000; long createdWhen = (long) (daysSinceEpoch * MILLIS_PER_DAY + startDate.getTimeInMillis()) - 2 * MILLIS_PER_DAY; return dateFormat.format(new Date(createdWhen)); }
From source file:io.seldon.spark.actions.JobUtils.java
public static long dateToUnixDays(String dateString) throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = dateFormat.parse(dateString); return ((date.getTime() / 1000) / 86400); }
From source file:org.apache.drill.yarn.core.DoYUtil.java
public static String toIsoTime(long timestamp) { // Uses old-style dates rather than java.time because // the code still must compile for JDK 7. DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); fmt.setTimeZone(TimeZone.getDefault()); return fmt.format(new Date(timestamp)); }