2

I'm using the following:

DateUtils.getRelativeDateTimeString(context, created, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH);

It shows the date in a US format (MM.dd.yy). How can I change it to dd.MM.yy? Thanks.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
TOMKA
  • 1,096
  • 13
  • 24
  • `DateUtils` works by letting you decide the content of your date/time string, but not the format. This is so that the local settings can determine the format, giving the user more control over how dates are seen. This can be important if your application is used in various countries where calendars differ. – Bryan Bryce Apr 03 '19 at 21:24

2 Answers2

1

You can format your date using SimpleDateFormat class. Here is the reference to it.

Yury
  • 20,618
  • 7
  • 58
  • 86
0

You can't use that method to format to your desired string format. You would have to use a different method or reformat the string after you obtained the value.

This example uses regular expression to replace pattern with desired format:

CharSequence dd =  DateUtils.
    getRelativeDateTimeString(this, created,
        DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS,
        DateUtils.FORMAT_ABBREV_MONTH
);
Log.i(TAG, dd.toString()
    .replaceAll("^(\\d{1,2})/(\\d{1,2})/(\\d{4})", "$2.$1.$3")); // yyyyy.MMMMM.dd, hh:mm aaa
John Giotta
  • 16,432
  • 7
  • 52
  • 82