我試圖使用SimpleDateFormat格式化由3個整數表示的日期。 它看起來像這樣:SimpleDateFormat android未按預期格式化
...
SimpleDateFormat sdfHour = new SimpleDateFormat("HH");
SimpleDateFormat sdfMinute = new SimpleDateFormat("mm");
SimpleDateFormat sdfSecond = new SimpleDateFormat("ss");
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getDefault());
int hours = c.get(Calendar.HOUR_OF_DAY);
int minutes = c.get(Calendar.MINUTE);
int seconds = c.get(Calendar.SECOND);
String string_hours = sdfHour.format(hours);
String string_minutes = sdfMinute.format(minutes);
String string_seconds = sdfSecond.format(seconds);
和
Log.d("tag", "Time string is: " + string_hours + ":" + string_minutes + ":" + string_seconds);
輸出總是
Time string is: 19:00:00
我在做什麼錯在這裏?
您期望的是什麼? – 2014-09-22 10:38:26