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

@SuppressLint("SimpleDateFormat")
static String setDate() {
    // add DateTime to filename
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    Date currentLocalTime = cal.getTime();
    SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
    date.setTimeZone(TimeZone.getDefault());
    _currentDate = date.format(currentLocalTime);

    return _currentDate;
}

From source file:Main.java

/**
 * Parse the Date String in mySQL format into date object
 * //from   ww  w  .j a  v a 2  s.  c  o m
 * @param SQLDate the date String in SQL format ("yyyy-MM-dd HH:mm:ss")
 * @return The date object corresponding to SQLDate
 */
public static Date parseSQLDate(String SQLDate) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    return sdf.parse(SQLDate, new ParsePosition(0));
}

From source file:Main.java

/**
 * Gives a number only string representing current time ("yyyyMMddHHmmss")
 * /* ww w.  j  a va  2 s  . c  om*/
 * @return The string representation of current time.
 */
public static String timeNumbers() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:Main.java

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

From source file:Main.java

public static String getTime(long millisecond, String format) {
    Date date = new Date(millisecond);
    String time = "";
    if (date != null) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        df.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
        time = df.format(date);// ww w.  j a  v a 2  s  .co  m
    }
    return time;
}

From source file:Main.java

public static String getTime(Long timestamp) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    Date date = new Date(timestamp * 1000);
    sdf.format(date);//from w w w  . j ava 2 s .c  o m
    return sdf.format(date);
}

From source file:Main.java

public static String toIsoDateFormat(Date date) {

    TimeZone timeZone = TimeZone.getDefault();
    boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone);

    String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    format.setTimeZone(timeZone);

    StringBuilder buffer = new StringBuilder(format.format(date));
    if (!utc) {/*from   w  w w.ja v a 2  s .c om*/
        buffer.insert(buffer.length() - 2, ':');
    }

    return buffer.toString();
}

From source file:Main.java

public static String getTimeStamp() {
    Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm aa dd-M-yyyy");
    simpleDateFormat.setTimeZone(TimeZone.getDefault());
    return simpleDateFormat.format(calendar.getTime());
}

From source file:Main.java

public static String getCurrentTime(String format) {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    String currentTime = sdf.format(date);
    return currentTime;
}

From source file:Main.java

/**
 * TO get current time(GMT)/*from  w  w w  .  j ava 2 s  . c om*/
 * 
 * @return current time at specific time zone
 */
public static String UtcDateNow() {
    SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    formatUTC.setTimeZone(TimeZone.getTimeZone("EST5EDT"));
    return formatUTC.format(new Date().getTime());
}