Here you can find the source of toEnglishDate(String stringDate)
Parameter | Description |
---|---|
stringDate | - string of Oracle date |
public static String toEnglishDate(String stringDate)
//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; } } }