Here you can find the source of toOracleTimestamp(String stringDate, int intFlag)
Parameter | Description |
---|---|
stringDate | - string of English time |
public static java.sql.Timestamp toOracleTimestamp(String stringDate, int intFlag)
//package com.java2s; import java.util.*; public class Main { /**// www .java2 s. c o m * given format of dd/mm/yyyy, and return Timestamp yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Timestamp Oracle date * author Vincent Yuen * version %I%, %G% */ public static java.sql.Timestamp toOracleTimestamp(String stringDate, int intFlag) { java.sql.Timestamp oracleDate = null; if (stringDate == null) return null; try { oracleDate = java.sql.Timestamp.valueOf(toOracleDatetime(stringDate, intFlag)); } catch (Exception e) { return null; } return oracleDate; } /** * given format of dd/mm/yyyy, and return Timestamp yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Timestamp Oracle date * author Vincent Yuen * version %I%, %G% */ public static java.sql.Timestamp toOracleTimestamp(String stringDate) { java.sql.Timestamp oracleDate = null; if (stringDate == null) return null; try { oracleDate = java.sql.Timestamp.valueOf(toOracleDatetime(stringDate)); } catch (Exception e) { return null; } return oracleDate; } /** * given format of dd/mm/yyyy and time, and return Timestamp yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Timestamp Oracle date * author Vincent Yuen * version %I%, %G% */ public static java.sql.Timestamp toOracleTimestamp(String stringDate, String stringDateTime) { java.sql.Timestamp oracleDate = null; if (stringDate == null) return null; try { oracleDate = java.sql.Timestamp.valueOf(toOracleDatetime(stringDate, stringDateTime)); } catch (Exception e) { return null; } return oracleDate; } /** * given format of dd/mm/yyyy, and return yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Oracle date * author Vincent Yuen * version %I%, %G% */ public static java.sql.Timestamp[] toOracleDatetime(String[] stringDate) { java.sql.Timestamp[] oracleDate = null; if (stringDate == null) return null; for (int i = 0; stringDate.length < i; i++) { oracleDate[i] = java.sql.Timestamp.valueOf(toOracleDatetime(stringDate[i])); } return oracleDate; } /** * given string and int object and return long * <p/> * <p/> * * @param stringDate - String * @param flag - int * @return long * author Vincent Yuen * version %I%, %G% */ public static String toOracleDatetime(String stringDate, int flag) { if (stringDate == null) { return "''"; } if (stringDate.trim().equals("")) { return "''"; } String oracleDate = toOracleDate(stringDate); if (flag == 0) oracleDate = oracleDate + " 00:00:00.000000000"; else if (flag == 1) oracleDate = oracleDate + " 23:59:59.000000000"; else oracleDate = toOracleDatetime(stringDate); return oracleDate; } /** * given format of dd/mm/yyyy, and return yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Oracle date * author Vincent Yuen * version %I%, %G% */ public static String toOracleDatetime(String stringDate) { if (stringDate == null) { return "''"; } if (stringDate.trim().equals("")) { return "''"; } String oracleDate = toOracleDate(stringDate); String zeros = "000000000"; Calendar calendar = Calendar.getInstance(); String h = "0" + calendar.get(Calendar.HOUR_OF_DAY); h = h.substring(h.length() - 2, h.length()); String mi = "0" + calendar.get(Calendar.MINUTE); mi = mi.substring(mi.length() - 2, mi.length()); String s = "0" + calendar.get(Calendar.SECOND); s = s.substring(s.length() - 2, s.length()); oracleDate = oracleDate + " " + h + ":" + mi + ":" + s + "." + zeros; oracleDate = oracleDate.trim(); int dividingSpace; dividingSpace = oracleDate.indexOf(' '); return oracleDate; } /** * given format of dd/mm/yyyy and String of time and return yyyy-mm-dd hh:mm:ss.000000000 * <p/> * <p/> * * @param stringDate - string of English time * @return Oracle date * author Vincent Yuen * version %I%, %G% */ public static String toOracleDatetime(String stringDate, String stringDateTime) { if (stringDate == null) { return "''"; } if (stringDate.trim().equals("")) { return "''"; } String spaceCh = ":"; String h = ""; String mi = ""; int spacePos = stringDateTime.indexOf(spaceCh); if (spacePos == -1) { h = stringDateTime.substring(0, 2); mi = stringDateTime.substring(2, 4); } else { h = stringDateTime.substring(0, spacePos); mi = stringDateTime.substring((spacePos + 1), stringDateTime.length()); } String oracleDate = toOracleDate(stringDate); String zeros = "000000000"; // Calendar calendar = Calendar.getInstance(); // h = stringDateTime.substring(0, 2); // mi = stringDateTime.substring(2, stringDateTime.length()); String s = "00"; oracleDate = oracleDate + " " + h + ":" + mi + ":" + s + "." + zeros; oracleDate = oracleDate.trim(); int dividingSpace; dividingSpace = oracleDate.indexOf(' '); return oracleDate; } /** * given format of dd/mm/yyyy, and return yyyy-mm-dd * <p/> * <p/> * * @param stringDate - string of English time * @return Oracle date * author Vincent Yuen * version %I%, %G% */ public static String toOracleDate(String stringDate) { String year = ""; String month = ""; String dateOfMonth = ""; // Calendar cal = Calendar.getInstance(); int checkyear = -1; // if the incoming value is empty string try { if (stringDate.trim().equals("")) { return "''"; } else { int index = stringDate.indexOf("/"); dateOfMonth = stringDate.substring(0, index); int lastIndex = stringDate.lastIndexOf("/"); year = stringDate.substring(lastIndex + 1, stringDate.length()); 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; } } // Log.debug((year+"-"+month+"-"+dateOfMonth)); return year + "-" + month + "-" + dateOfMonth; } } catch (Exception e) { return ""; } } }