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 SimpleDateFormat getDateFormat() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
    format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
    return format;
}

From source file:Main.java

public static long dateToMilli(String dateString) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    sdf.setTimeZone(TimeZone.getDefault());
    try {/*from   ww w  . ja v a2 s .  c om*/
        return sdf.parse(dateString).getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

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

From source file:Main.java

/**
 * Turns a Java date object into a mySQL acceptable date string
 * // w w  w.ja v  a2 s .  co  m
 * @param date
 *            Date object
 * @return mySQL acceptable date string
 */
public static String toSQLDateTimeString(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.format(date);
}

From source file:Main.java

public static SimpleDateFormat getDateTimeFormat() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
    format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
    return format;
}

From source file:Main.java

/**
 * Get the current date and time in SQL date format ("yyyy-MM-dd HH:mm:ss")
 * //from  w  ww  .ja v a2s.co m
 * @return String representing current date and time
 */
public static String timeNow() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:Main.java

private static String getFormattedStringFromDate(Date date) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return simpleDateFormat.format(date);
}

From source file:Main.java

public static String timestamp2String(Timestamp timestamp, String pattern, Locale locale) {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale);
    simpleDateFormat.setTimeZone(TimeZone.getDefault());

    return simpleDateFormat.format(timestamp);
}

From source file:Main.java

public static String getTimeStamp() {
    Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getDefault());
    return simpleDateFormat.format(calendar.getTime());
}

From source file:Main.java

public static String getImageName() {
    Date date = new Date();
    SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", new Locale("en"));
    dFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return "Wallpaper-" + dFormat.format(date) + ".jpg";
}