I know I can use android.text.format.DateFormat.getDateFormat()
to format my dates, and android.text.format.DateFormat.getTimeFormat
to format my times, but how do I format a datetime? Similar to the getDateTimeInstance
method from java.text.DateFormat
.
I'm currently just concatenating the result of both the getDateFormat
and getTimeFormat
's formatters, but I don't know which way around the user prefers to have their dates and times shown.
Use the toLocaleString() method to get a date and time in the user's locale format, e.g. date. toLocaleString() . The toLocaleString method returns a string representing the given date according to language-specific conventions.
Use the DateTime. ToString() method to convert the date object to string with the local culture format.
Do you need the String representation only? If yes, please have a look atDateUtils.formatDateTime(Context context, long millis, int flags)
:
public static String formatDateTime (Context context, long millis, int flags)
in: android.text.format.DateUtils
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With