我希望获得给定格式的系统时间。我正在使用以下代码块。首先,我将时间作为字符串以我想要的格式,然后我尝试将其转换为真正的Date对象,但它不会转换为我想要的格式。我做错了什么?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String currentDateandTime = sdf.format(new Date(System.currentTimeMillis()));
Date convertedDate;
try {
convertedDate = sdf.parse(currentDateandTime);
Log.d("Time", "yyyy-MM-dd'T'HH:mm:ss.SSSZ " + currentDateandTime +" "+convertedDate);
} catch (ParseException e) {
e.printStackTrace();
}
这是logcat输出
07-03 15:41:43.783: D/Time(2975): yyyy-MM-dd'T'HH:mm:ss.SSSZ 2012-07-03T15:41:43.783Z Tue Jul 03 15:41:43 EEST 2012
感谢您的帮助。