Example usage for java.text DateFormat setTimeZone

List of usage examples for java.text DateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text DateFormat 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:Main.java

public static String toSimpleDateTime(Date date) {
    DateFormat df = new SimpleDateFormat(simpleDateString, Locale.UK);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df.format(date);
}

From source file:Main.java

public static String DateTimeToString(Date d) {
    DateFormat formatter;

    formatter = new SimpleDateFormat("dd-MM-yyyy-HH-mm");
    formatter.setTimeZone(TimeZone.getTimeZone("EST"));

    String s = new StringBuilder(formatter.format(d)).toString();
    return s;//from   w  ww.j  a  va 2 s  .c  o m
}

From source file:Util.java

public static long getLocalEpoch(TimeZone timezone) {
    DateFormat dateFormat = DateFormat.getInstance();
    if (timezone != null)
        dateFormat.setTimeZone(timezone);
    long result = 0;
    try {//from   w  w w .  j a va 2s  .  c  o  m
        result = DateFormat.getInstance().parse("01/02/70 12:00 AM").getTime();
    } catch (ParseException e) {

    }

    if (dateFormat.getTimeZone().inDaylightTime(new Date())) {
        result -= 60 * 60 * 1000;
    }
    return result;
}

From source file:Main.java

public static String getGMTDate(Date date) {
    if (date == null) {
        return null;
    }/* ww  w.j  a va2  s. co  m*/
    DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    String dateStr = dateFormat.format(date);
    return dateStr;
}

From source file:Main.java

private static DateTime getDateFromISO(String ISOString) {
    //DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
    try {//from  w ww. ja va2  s .c  o  m
        return parser.parseDateTime(ISOString);
    } catch (Throwable e) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            return new DateTime(df.parse(ISOString));
        } catch (Throwable ignored) {
            Log.d("ERROR", "Failed parsing string into date");
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

public static String getCurrentUtcTime() {
    Date l_datetime = new Date();
    DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
    TimeZone l_timezone = TimeZone.getDefault();
    formatter.setTimeZone(l_timezone);
    String l_utc_date = formatter.format(l_datetime);
    return l_utc_date;
}

From source file:org.sifassociation.util.SIFAuthUtil.java

public static String getTimestamp() {
    TimeZone timeZone = TimeZone.getTimeZone("UTC");
    DateFormat dateFormat = new SimpleDateFormat(ISO8601);
    dateFormat.setTimeZone(timeZone);
    return dateFormat.format(new Date());
}

From source file:fitnesse.components.Logger.java

private static String format(DateFormat format, Calendar calendar) {
    DateFormat tmpFormat = (DateFormat) format.clone();
    tmpFormat.setTimeZone(calendar.getTimeZone());
    return tmpFormat.format(calendar.getTime());
}

From source file:org.springframework.cloud.stream.metrics.config.MetricJsonSerializer.java

private static DateFormat defaultDateFormat() {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df;/*from   w w w. j  a v a 2  s  . co  m*/
}

From source file:Main.java

/**
 * getDateAsString/*from  w w w  . j  ava  2  s  .  c om*/
 * Convert a date into a string
 *
 * @param date   the date
 * @param format the format in which to return the string
 * @return the new formatted date string
 */
public static String getDateAsString(Date date, String format, String timezone) {
    DateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    if (timezone == null) {
        formatter.setTimeZone(TimeZone.getDefault());
    } else {
        formatter.setTimeZone(TimeZone.getTimeZone(timezone));
    }
    return formatter.format(date);
}