Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

In this page you can find the example usage for java.util TimeZone getTimeZone.

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

From source file:Main.java

public static GregorianCalendar fromXSDateTime(String dateTime) throws DatatypeConfigurationException {
    GregorianCalendar cal = null;

    if (dateTime != null && dateTime.length() != 0) {
        cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime).toGregorianCalendar();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    }/*from ww w . j ava 2s .  co m*/

    return cal;
}

From source file:Main.java

public static String my_time_in(String target_time_zone, String format) {
    TimeZone tz = TimeZone.getTimeZone(target_time_zone);
    Date date = Calendar.getInstance().getTime();
    SimpleDateFormat date_format_gmt = new SimpleDateFormat(format);
    date_format_gmt.setTimeZone(tz);/*from   www  .  jav a 2 s.c om*/
    return date_format_gmt.format(date);
}

From source file:Main.java

public static Date ConvertFromWebService(String strDate) {
    String[] formats = new 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 (String frm : formats) {
        try {//from  w  ww  . j a  v  a2s  .c om
            SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            return format.parse(strDate);
        } catch (Exception ex) {
        }
    }
    return null;
}

From source file:Main.java

/**
 * Converts a Date to the GMT timezone and formats it to the format yyyy-MM-dd HH:mm:ssZ.
 *
 * @param date the Date to parse.//from   ww  w .j  a v a2  s.  c  o  m
 * @return A formatted date string.
 */
public static String getLongGmtDateString(Date date) {
    if (date == null) {
        return null;
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return simpleDateFormat.format(date);
}

From source file:Main.java

public static Calendar parseCalendarString(String dateTimeString) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date date = null;// ww  w  .  ja v a  2s  .com
    try {
        date = dateFormat.parse(dateTimeString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm"));
    cal.setTime(date);
    return cal;
}

From source file:Main.java

public static String StampToyyyyMMdd(long stamp) {

    Date date = null;//from w w w  .  jav a2s  .c  o  m
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    date = calendar.getTime();

    String format = "yyyy-MM-dd";
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
    sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

    return sdf.format(date);

}

From source file:Main.java

public static String getFormatDate(final Date date, String type) {
    if (null == date || TextUtils.isEmpty(type)) {
        return null;
    }/*from   w  w w.j a  va2s.c  om*/

    SimpleDateFormat sdf;
    try {
        sdf = new SimpleDateFormat(type, Locale.SIMPLIFIED_CHINESE);
    } catch (Exception e) {
        sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    }
    TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
    sdf.setTimeZone(timeZone);
    return sdf.format(date);
}

From source file:Main.java

public static String getDateForHistory(String dateString) {
    String[] shortMonths = new DateFormatSymbols().getShortMonths();

    SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat formater = new SimpleDateFormat("dd");
    String month = "";

    parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
    formater.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = null;/*from w w  w .j a va2  s . c  om*/
    try {
        parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
        date = parserSDF.parse(dateString);
        month = shortMonths[date.getMonth()];
    } catch (ParseException e) {
        Log.d(TAG, e.getMessage());
    }

    return month + " " + formater.format(date);
}

From source file:Main.java

public static Date ConvertFromWebService(final String strDate) {

    final String[] formats = new 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 (final String frm : formats) {
        try {//from   ww  w. j  av  a  2 s  .  c o m
            final SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            return format.parse(strDate);
        } catch (final Exception ex) {
            Log.e("IGWHelper", "Failed to convert Web Service Date.", ex);
        }
    }
    return null;
}

From source file:Main.java

public static String StampToStringMMddHHmm(long stamp) {

    Date date = null;//from   ww  w.  j a  va 2s.  co m
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    date = calendar.getTime();

    //       String format = "yyyy-MM-dd HH:mm:ss.SSSZ"; 
    String format = "MM-dd HH:mm";
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
    sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

    return sdf.format(date);

}