I have a String
which is 2013-8-25, 16:33
, now I need to convert it into Date
. For this purpose I use:
Date mDate = new SimpleDateFormat("yyyy-MM-dd, HH:mm").parse("2013-8-25, 16:33");
Then I need to get a String
of proper pattern, which is
private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
and here is how I do it:
public static String convertDateToString(Date date) {
String string = DateFormat.format(DATE_PATTERN, date).toString();
Logger.logVerbose(TAG, "Date converted into String is " + string);
return string;
}
but:
Date converted into String is 2013-08-25THH:33:00.SSSZ
Why hours are still HH
? Thanks!
I strongly suspect that you're running into a compatibility issue with DateFormat
. In particular, from the documentation:
The format methods in this class implement a subset of Unicode UTS #35 patterns. The subset currently supported by this class includes the following format characters: acdEHhLKkLMmsyz. Up to API level 17, only adEhkMmszy were supported. Note that this class incorrectly implements k as if it were H for backwards compatibility.
I suggest you use SimpleDateFormat
for formatting, to avoid this issue.
See more on this question at Stackoverflow