B4J Question How to localize date format

Discussion in 'B4J Questions' started by HARRY, Mar 26, 2015.

  1. HARRY

    HARRY Active Member Licensed User


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

    rwblinn Well-Known Member Licensed User


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

    '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
  3. Troberg

    Troberg Well-Known Member Licensed User

    Something like this, but with other format strings (this formats as a standard ISO date):

    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
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice