Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display date AND time in user locale

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.

like image 592
Sverre Rabbelier Avatar asked Jun 06 '10 10:06

Sverre Rabbelier


People also ask

How do I get locale time?

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.

Which method is used to convert a date to a string in the current users locale?

Use the DateTime. ToString() method to convert the date object to string with the local culture format.


1 Answers

Do you need the String representation only? If yes, please have a look at
DateUtils.formatDateTime(Context context, long millis, int flags):

public static String formatDateTime (Context context, long millis, int flags)

in: android.text.format.DateUtils

like image 144
Loxley Avatar answered Sep 19 '22 03:09

Loxley