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 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

/**
 * Convert to String a date that is received as parameter.
 *
 * @param date the date//from  w w w. java2  s  .  c o m
 * @return String
 */

public static String toStringDate(Date date) {
    String formatoFecha = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    SimpleDateFormat sdf = new SimpleDateFormat(formatoFecha);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return date == null ? null : URLEncoder.encode(sdf.format(date));
}

From source file:Main.java

public static long stringDateToLong(String dateStr) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
    Date date = null;/*from  w ww  .ja  va 2s  .  c  om*/
    try {
        date = sdf.parse(dateStr);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return date.getTime();
}

From source file:Main.java

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

    return _currentDateTime;
}

From source file:Main.java

public static String getTimeStampForDatabase() {
    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 SimpleDateFormat getDateTimeFormat() {
    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

public static java.util.Date ConvertFromWebService(String strDate) {
    java.lang.String[] formats = new java.lang.String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS",
            "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" };
    for (java.lang.String frm : formats) {
        try {//  w w w. j a  v a2s .c  om
            SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
            format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
            return format.parse(strDate);
        } catch (java.lang.Exception ex) {
        }
    }
    return null;
}

From source file:Main.java

public static int StampToDateInt(long stamp) {
    int date = 0;

    Date datetime = null;/*from www .j a  v a  2s. c om*/
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    datetime = calendar.getTime();

    String format = STAMP_TO_DATE_INT;
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setTimeZone(TimeZone.getTimeZone(TIME_ZONE_PRC));

    try {
        date = Integer.parseInt(sdf.format(datetime));
    } catch (Exception e) {
        e.printStackTrace();
    }
    //Log.i("StampHelper", "date_int:"+date);
    return date;
}

From source file:Main.java

public static Date getDateFromString(String inputString) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = null;//from  ww  w .ja v  a2  s  .  c  o  m
    try {
        date = sdf.parse(inputString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static String getTimestamp() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
    sdf.setTimeZone(TimeZone.getDefault());
    String tmp = sdf.format(new Date());
    tmp = tmp.substring(0, 22) + ":" + tmp.substring(22);
    return tmp;// w w  w.j ava  2  s.  c o m
}