Shared publicly  - 
 
In Android, to get a properly formatted and localized date/time value that respects your regional language and 24 hour preference settings, e.g., "Nov 28, 2012 15:42", use this code:

   String datePattern = ((SimpleDateFormat) DateFormat.getMediumDateFormat(BIMobile.getAppContext())).toLocalizedPattern();
   String timePattern = ((SimpleDateFormat) DateFormat.getTimeFormat(BIMobile.getAppContext())).toLocalizedPattern();
   String dateTimePattern = datePattern + " " + timePattern;
   SimpleDateFormat dateTimeFormat = new SimpleDateFormat(dateTimePattern );

You'll also need to use the 

   @SuppressLint("SimpleDateFormat")

annotation to get rid of Lint warnings.
10
6
Sergey Povzner's profile photoDanny Fürniß's profile photoRemel Pugh's profile photoEdouard Marquez's profile photo
6 comments
 
These are the kind of things that I hate about the Android SDK. There should be a simple method like DateUtils.getUserDateFormatted(). Same goes for location stuff. 
 
We can certainly start an open source library that starts collecting snippets like this. Everyone has a couple items like this that can make it into a ___Utils class.
 
Another set of DateUtils I have is for dealing with ISO 8601 dates
 
Don't use @SuppressLint("SimpleDateFormat"); instead, fix the code as suggested by lint and use
new SimpleDateFormat(dateTimePattern, Locale.getDefault())
Add a comment...