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:Main.java

public static Date getDateFromString(String format, String dateString) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    return sdf.parse(dateString);
}

From source file:TimeUtils.java

public static String formatDuration(long duration) {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss:SSS");
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    return format.format(new Date(duration));
}

From source file:Main.java

public static String getUTCDateTimeAsStringTemp() {
    final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    final String utcTime = sdf.format(new Date());

    return utcTime;
}

From source file:Main.java

public static String toNumberDate(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.format(date);
}

From source file:Main.java

public static SimpleDateFormat getDateFormat() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
    return format;
}

From source file:Main.java

public static String getDateTimeTextFromTimestamp(Long timestamp) {
    Timestamp stamp = new Timestamp(timestamp);
    Date date = new Date(stamp.getTime());
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat s = new SimpleDateFormat("dd MMM yyyy HH:mm");
    s.setTimeZone(cal.getTimeZone());
    return s.format(date);
}

From source file:Main.java

public static DateFormat GetFileNameDateFormatter() {
    Locale loc = new Locale("en", "US");
    SimpleDateFormat df = new SimpleDateFormat("MM.dd.yy.h.mm.ss", loc);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df;/*  w w  w . j  a  va2 s . c  o  m*/
}

From source file:Main.java

/**
 * Turns a Java date object into a mySQL acceptable date string
 *
 * @param date/*from ww w. ja  v a 2  s  .com*/
 *            Date object
 * @return mySQL acceptable date string
 */
public static String toSQLDateString(Date date, String timezone) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setTimeZone(TimeZone.getTimeZone(timezone));
    return dateFormat.format(date);
}

From source file:Main.java

/**
 * Get formatted date string/*from w ww.j a  v  a 2  s .  c  o m*/
 */
public static String getFormattedDateString(Date date, String format) {
    Calendar cal = Calendar.getInstance();
    TimeZone timeZone = cal.getTimeZone();

    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
    dateFormat.setTimeZone(timeZone);

    return dateFormat.format(date);
}

From source file:Main.java

public static SimpleDateFormat getDateFormat() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
}