Here you can find the source of toEnglishDateTime(java.sql.Timestamp ts)
Parameter | Description |
---|---|
ts | - Timestamp |
public static String toEnglishDateTime(java.sql.Timestamp ts)
//package com.java2s; public class Main { /**/*from ww w. j ava 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 toEnglishDateTime(java.sql.Timestamp ts) { String oracleDate = ""; if (ts != null) { oracleDate = ts.toString().substring(0, 16); oracleDate = toEnglishDateTime(oracleDate); } return oracleDate; } /** * given format of (yyyy-mm-dd hh:mm:ss.000000000 or yyyy-mm-dd) , and return dd/mm/yyyy hh:mm * <p/> * <p/> * * @param stringDateTime - string of Oracle date * @return stringDate - string of English time * author Vincent Yuen * version %I%, %G% */ public static String toEnglishDateTime(String stringDateTime) { String displayDateTime = toEnglishDate(stringDateTime); if (displayDateTime == null || displayDateTime.trim().equals("")) return "''"; else { int index = stringDateTime.indexOf(":"); displayDateTime = displayDateTime + " " + stringDateTime.substring(index - 2, index + 3); return displayDateTime; } } /** * 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; } } }