Date format from MM/DD/YYYY to DD/MM/YYYY

2009-01-14
2013-05-02
  • Gavin Hogan

    Gavin Hogan - 2009-01-14

    Hi all,

    just wondering if anyone knows, we currently have the Australian Language pack installed but want the date format changed from US to AU/UK in the format of DD/MM/YYYY.

    any help would be appreciated

     
    • albert

      albert - 2009-01-14

      Please use correct Locale setting
      Let function getLocale() work for you ...

      Otherwise change Default

      from

      @return date format MM/dd/yyyy

      to

      @return date format dd/MM/yyyy

      And

      Replace the line:

      m_dateFormat.applyPattern("yyyy-MM-dd");

      to

      m_dateFormat.applyPattern("dd/MM/yyyy ");

      for UK - Australia Country..

      We free customize for woldwide user...

      /**
           *  Get (Short) Date Format.
           *  The date format must parseable by org.compiere.grid.ed.MDocDate
           *  i.e. leading zero for date and month
           *  @return date format MM/dd/yyyy - dd.MM.yyyy
           */
          public SimpleDateFormat getDateFormat()
          {
              if (m_dateFormat == null)
              {
                  m_dateFormat = (SimpleDateFormat)DateFormat.getDateInstance
                      (DateFormat.SHORT, m_locale);
                  String sFormat = m_dateFormat.toPattern();
                  //    some short formats have only one M and d (e.g. ths US)
                  if (sFormat.indexOf("MM") == -1 && sFormat.indexOf("dd") == -1)
                  {
                      String nFormat = "";
                      for (int i = 0; i < sFormat.length(); i++)
                      {
                          if (sFormat.charAt(i) == 'M')
                              nFormat += "MM";
                          else if (sFormat.charAt(i) == 'd')
                              nFormat += "dd";
                          else
                              nFormat += sFormat.charAt(i);
                      }
                  //    log.finer(sFormat + " => " + nFormat);
                      m_dateFormat.applyPattern(nFormat);
                  }
                  //    Unknown short format => use JDBC
                  if (m_dateFormat.toPattern().length() != 8)
                      m_dateFormat.applyPattern("yyyy-MM-dd");

       

Log in to post a comment.