B4J Question How to localize date format

HARRY

Active Member
Licensed User
Hi,

I want to localize the date format from English to Dutch: e.g. 23 Mar 2015 should read 23 mrt 2015.
Is that possible?
Harry
 

rwblinn

Well-Known Member
Licensed User
Hi,

one possible way is using Inline Java. There might be other solutions.

B4X:
'Get a localized date
'Parameter: Date as Long
'Parameter: Locale as string, like nl, uk, us etc.
'Example B4J:
'Global Private joInline As JavaObject = Me
'Log("Date Localized NL = " & joInline.RunMethod("getDateLocalized", Array(DateTime.Now, "nl")))
'Log("Date Localized US = " & joInline.RunMethod("getDateLocalized", Array(DateTime.Now, "us")))
#If JAVA
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

  public static String getDateLocalized(long mdate, String mlocale) {
  int style = DateFormat.MEDIUM;   //Other Dateformat styles: FULL, SHORT
   DateFormat df=null;
   df = DateFormat.getDateInstance(style, new Locale(mlocale));
   return df.format(mdate);
  }
#End If
 

Troberg

Well-Known Member
Licensed User
Something like this, but with other format strings (this formats as a standard ISO date):

B4X:
Sub DateToISO(Date As Long) As String
  DateTime.DateFormat = "yyyy-MM-dd"
  DateTime.TimeFormat = "HH:mm:ss"
  Return DateTime.Date(Date) & " " & DateTime.Time(Date)
End Sub
 
Top