Android : SimpleDateFormat android not formatting as expected

on Monday, September 22, 2014


I'm trying to use SimpleDateFormat for formatting a date represented by 3 ints. It looks like this:



...
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);


and the output of



Log.d("tag", "Time string is: " + string_hours + ":" + string_minutes + ":" + string_seconds);


is always



Time string is: 19:00:00


What am I doing wrong here?


0 comments:

Post a Comment