Created
August 8, 2014 07:28
-
-
Save AHarazim/f773097cfd1308227556 to your computer and use it in GitHub Desktop.
Localised Date in Andorid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String formatDate(Date date, boolean withTime) { | |
String result = ""; | |
DateFormat dateFormat; | |
if (date != null) { | |
try { | |
String format = Settings.System.getString(mContext.getContentResolver(), Settings.System.DATE_FORMAT); | |
if (TextUtils.isEmpty(format)) { | |
dateFormat = android.text.format.DateFormat.getDateFormat(mContext); | |
} else { | |
dateFormat = new SimpleDateFormat(format); | |
} | |
result = dateFormat.format(date); | |
if (withTime) { | |
dateFormat = android.text.format.DateFormat.getTimeFormat(mContext); | |
result += " " + dateFormat.format(date); | |
} | |
} catch (Exception e) { | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment