Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:com.cloudbees.jenkins.support.SupportPlugin.java

private static void appendManifestHeader(StringBuilder manifest) {
    SupportPlugin plugin = SupportPlugin.getInstance();
    SupportProvider supportProvider = plugin == null ? null : plugin.getSupportProvider();
    String bundleName = (supportProvider == null ? "Support" : supportProvider.getDisplayName())
            + " Bundle Manifest";
    manifest.append(bundleName).append('\n').append(StringUtils.repeat("=", bundleName.length()))
            .append("\n\n");
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
    f.setTimeZone(TimeZone.getTimeZone("UTC"));
    manifest.append("Generated on ").append(f.format(new Date())).append("\n\n");
}

From source file:com.cloudbees.jenkins.support.SupportPlugin.java

/**
 * Returns the full bundle name./*  w  w  w. j av a2 s.  co m*/
 *
 * @return the full bundle name.
 */
@NonNull
public static String getBundleFileName() {
    StringBuilder filename = new StringBuilder();
    filename.append(getBundlePrefix());

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    filename.append("_").append(dateFormat.format(new Date()));

    filename.append(".zip");
    return filename.toString();
}

From source file:com.cloudbees.jenkins.support.SupportPlugin.java

@Initializer(after = InitMilestone.STARTED)
public static void threadDumpStartup() throws Exception {
    if (!logStartupPerformanceIssues)
        return;/*  ww w. ja  v  a 2 s .  c om*/
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    final File f = new File(getRootDirectory(), "/startup-threadDump" + dateFormat.format(new Date()) + ".txt");
    if (!f.exists()) {
        try {
            f.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Thread t = new Thread("Support core plugin startup diagnostics") {
        @Override
        public void run() {
            try {
                while (true) {
                    final Jenkins jenkins = Jenkins.getInstanceOrNull();
                    if (jenkins == null || jenkins.getInitLevel() != InitMilestone.COMPLETED) {
                        continue;
                    }
                    try (PrintStream ps = new PrintStream(new FileOutputStream(f, true), false, "UTF-8")) {
                        ps.println("=== Thread dump at " + new Date() + " ===");
                        ThreadDumps.threadDump(ps);
                        // Generate a thread dump every few seconds/minutes
                        ps.flush();
                        TimeUnit.SECONDS.sleep(secondsPerThreadDump);
                    } catch (FileNotFoundException | UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
                Thread.currentThread().interrupt();
            }
        }
    };
    t.start();
}

From source file:com.jkoolcloud.tnt4j.core.UsecTimestamp.java

/**
 * Returns the string representation of the timestamp based on the specified
 * format pattern, milliseconds and microseconds.
 *
 * @param pattern format pattern/*from   ww  w. ja  v a  2  s . com*/
 * @param tz time zone
 * @param msecs milliseconds
 * @param usecs microseconds
 * @return formatted date/time string based on pattern
 */
public static String getTimeStamp(String pattern, TimeZone tz, long msecs, long usecs) {
    String tsStr = null;

    if (pattern == null) {
        SimpleDateFormat df = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss.SSS" + String.format("%03d", usecs) + " z");
        df.setTimeZone(tz);
        tsStr = df.format(new Date(msecs));
    }

    if (tsStr == null) {
        int fracSecPos = pattern == null ? -1 : pattern.indexOf('S');
        if (fracSecPos < 0) {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            df.setTimeZone(tz);
            tsStr = df.format(new Date(msecs));
        }
    }

    if (tsStr == null) {
        String usecStr = String.format("%03d", usecs);
        pattern = pattern.replaceFirst("SS*", "SSS" + usecStr);
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        df.setTimeZone(tz);
        tsStr = df.format(new Date(msecs));
    }

    return tsStr.replace(" Z", " 00:00");
}

From source file:com.microsoft.azurebatch.jenkins.azurebatch.AzureBatchHelper.java

/**
 * Create a random job Id./*from ww  w .j a va  2  s .  co  m*/
 * @return job Id
 * @param tag tag for job Id
 */
public static String createJobId(String tag) {
    SimpleDateFormat dateFormatUtc = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormatUtc.setTimeZone(TimeZone.getTimeZone("UTC"));
    String utcTime = dateFormatUtc.format(new Date());

    String jobIdPrefix = "jenkins-" + tag;
    return jobIdPrefix + "-" + utcTime + "-" + UUID.randomUUID().toString().replace("-", "");
}

From source file:com.funambol.exchange.util.DateTools.java

/**
 * Make a date from a webdav tag date//from   www .  ja  v  a2 s.  co  m
 * 
 * @param date
 *            webdav tag content
 * @return a Date
 * @throws XmlParseException
 */
public static Date webDavTagToDate(String date) throws XmlParseException {

    SimpleDateFormat formatter;
    String value;
    Date timestamp;

    try {

        if (date != null && date.length() > 23) {
            value = date.substring(0, 10) + " " + date.substring(11, 23);

            formatter = new SimpleDateFormat(DATE_FORMAT_WEBDAV_FROM_EXCHANGE);
            formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
            timestamp = formatter.parse(value);
        } else {
            timestamp = null;
        }
    } catch (ParseException e) {
        throw new XmlParseException(e.toString());
    }

    return timestamp;

}

From source file:com.funambol.exchange.util.DateTools.java

/**
 * Make a date from a webdav tag date//w  w  w  . j a  va2  s  . c om
 * 
 * @param date
 *            webdav tag content
 * @param timeZone
 * @return a Date
 * @throws XmlParseException
 */
public static String webDavTagToPDIDate(String date, TimeZone timeZone) throws XmlParseException {

    SimpleDateFormat formatter;

    if (timeZone == null) {
        timeZone = TimeZone.getTimeZone("GMT");
    }

    Date dt;
    String pdiDate;

    if (date != null && date.length() > 0) {

        dt = webDavTagToDate(date);

        formatter = new SimpleDateFormat(DATE_FORMAT_PDI);
        formatter.setTimeZone(timeZone);
        pdiDate = formatter.format(dt);

    } else {
        pdiDate = null;
    }

    return pdiDate;
}

From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java

/**
 * Formats a opendata-time-value to utc time
 * @param textual_date e.g. 2013-07-19 41:35
 * @return the date value OR -1 if the format is invalid
 * dz: add seconds/*w  w w.  j a  v  a2s . c o m*/
 */
private static long parseDate(final String textual_date) {
    final SimpleDateFormat date_formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    date_formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    try {
        return date_formatter.parse(textual_date).getTime();
    } catch (ParseException ex) {
        return -1;
    }
}

From source file:com.example.app.support.service.AppUtil.java

/**
 * Get the date format fixed to UTC.
 *
 * @param locale the locale./* ww w.  j a  va2 s.c  o m*/
 * @param pattern the date format pattern
 *
 * @return the date format.
 */
public static SimpleDateFormat getDateFormat(Locale locale, @Nullable String pattern) {
    final SimpleDateFormat format = new SimpleDateFormat(ofNullable(pattern).orElse("MMM d, yyyy"), locale);
    format.setTimeZone(UTC);
    return format;
}

From source file:eionet.cr.util.odp.ODPDatasetsPacker.java

/**
 *
 * @return// ww  w.jav a  2 s .  c om
 */
private static DateFormat buildXmlSchemaDateFormat() {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf;
}