(written at 2013-03-22 15:18:54)
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import android.util.Log;
public class TimezoneTransform {
public static String transform(String from){
String to = "";
SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
//本地时区
Calendar nowCal = Calendar.getInstance();
TimeZone localZone = nowCal.getTimeZone();
//设定SDF的时区为本地
simple.setTimeZone(localZone);
//把字符串转化为Date对象,然后格式化输出这个Date
Date fromDate = new Date();
try {
fromDate = simple.parse(from);
to = simple.format(fromDate);
} catch (ParseException e1) {
e1.printStackTrace();
}
return to;
}
}