Java SQL Date Convert toEnglishDate(String stringDate)

Here you can find the source of toEnglishDate(String stringDate)

Description

given format of (yyyy-mm-dd hh:mm:ss.000000000 or yyyy-mm-dd) , and return dd/mm/yyyy

License

Open Source License

Parameter

Parameter Description
stringDate - string of Oracle date

Return

stringDate - string of English time author Vincent Yuen version %I%, %G%

Declaration

public static String toEnglishDate(String stringDate) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  ww  w.  ja v  a 2  s .  c  om*/
     * given timestamp object and return string format of yyyy-mm-dd
     * <p/>
     * <p/>
     *
     * @param ts - Timestamp
     * @return String
     *         author    Vincent Yuen
     *         version    %I%, %G%
     */
    public static String toEnglishDate(java.sql.Timestamp ts) {
        String oracleDate = "";
        if (ts != null) {
            oracleDate = ts.toString().substring(0, 10);
            oracleDate = toEnglishDate(oracleDate);
        }
        return oracleDate;
    }

    /**
     * given format of (yyyy-mm-dd hh:mm:ss.000000000 or yyyy-mm-dd) , and return dd/mm/yyyy
     * <p/>
     * <p/>
     *
     * @param stringDate - string of Oracle date
     * @return stringDate - string of English time
     *         author    Vincent Yuen
     *         version    %I%, %G%
     */
    public static String toEnglishDate(String stringDate) {
        String year = "";
        String month = "";
        String dateOfMonth = "";
        stringDate = stringDate.toString().substring(0, 10);
        //   Calendar cal = Calendar.getInstance();
        int checkyear = -1;
        // if the incoming value is empty string
        if (stringDate.trim().equals("")) {
            return "''";
        } else {
            int index = stringDate.indexOf("-");
            year = stringDate.substring(0, index);
            int lastIndex = stringDate.lastIndexOf("-");
            dateOfMonth = stringDate.substring(lastIndex + 1, lastIndex + 3);
            month = stringDate.substring(index + 1, lastIndex);

            dateOfMonth = "0" + dateOfMonth;
            dateOfMonth = dateOfMonth.substring(dateOfMonth.length() - 2, dateOfMonth.length());
            month = "0" + month;
            month = month.substring(month.length() - 2, month.length());
            if (year.length() == 2) {
                checkyear = 10 * (Integer.parseInt(year.substring(0, 1))) + Integer.parseInt(year.substring(1, 2));
                if (checkyear >= 50) {
                    year = "19" + year;
                } else {
                    year = "20" + year;
                }
            }
            return dateOfMonth + "/" + month + "/" + year;
        }

    }
}

Related

  1. to_char(Date date, String format)
  2. toBigDecimal(@Nullable final Date value)
  3. toCalender(final Date aDate)
  4. todaySqlDate()
  5. toDBDate(String str)
  6. toGMT(final Date ts)
  7. toInt(java.util.Date v)
  8. toIntDate(Object object, int iDefault)
  9. toJavaDate(java.sql.Date date)