Android 时间字符串 转成UTC时间转为指定时间的时间字符串

1.
传送的UTC时间转换为指定时区的时间.
String  destTime = "2017-03-06 18-09-18";
String dateTime = converTime(destTime, TimeZone.getTimeZone("GMT"));

/**
 * 将传送的UTC时间转换为指定时区的时间.
 * */
private String converTime(String srcTime, TimeZone timezone) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    String convertTime = "";
    Date resultDate;

    
    try { // 将输入时间字串转换为UTC时间

        resultDate = sdf.parse(srcTime);
        Calendar cd = Calendar.getInstance();
        cd.setTimeInMillis(resultDate.getTime());

        SimpleDateFormat sdfGmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        sdfGmt.setTimeZone(timezone);
        convertTime = sdfGmt.format(cd.getTime()); 

    } catch (Exception e) {
        return convertTime;
    }

    return convertTime;
}

你可能感兴趣的:(android,知识点,android,UI)