Java Timestamp Parse String2Timestamp(String strInputDate)

Here you can find the source of String2Timestamp(String strInputDate)

Description

String Timestamp

License

Open Source License

Declaration

public static java.sql.Timestamp String2Timestamp(String strInputDate) 

Method Source Code

//package com.java2s;

public class Main {
    public static java.sql.Timestamp String2Timestamp(String strInputDate) {
        String strDate = strInputDate;
        int i, nYear, nMonth, nDay;
        String strSub = null;/*w w w.  j a v  a2s . c o  m*/
        i = strDate.indexOf("/");
        if (i < 0) {
            return createTimestamp();
        }
        strSub = strDate.substring(0, i);
        nDay = (new Integer(strSub.trim())).intValue();
        strDate = strDate.substring(i + 1);
        i = strDate.indexOf("/");
        if (i < 0) {
            return createTimestamp();
        }
        strSub = strDate.substring(0, i);
        nMonth = (new Integer(strSub.trim())).intValue() - 1; // Month begin from 0 value
        strDate = strDate.substring(i + 1);
        if (strDate.length() < 4) {
            if (strDate.substring(0, 1).equals("9")) {
                strDate = "19" + strDate.trim();
            } else {
                strDate = "20" + strDate.trim();
            }
        }
        nYear = (new Integer(strDate)).intValue();
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.set(nYear, nMonth, nDay);
        return new java.sql.Timestamp((calendar.getTime()).getTime());
    }

    public static java.sql.Timestamp createTimestamp() {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        return new java.sql.Timestamp((calendar.getTime()).getTime());
    }
}

Related

  1. parseToDate(String timestamp, String pattern)
  2. str2Timestamp(String str)
  3. String2Timestamp(String date)
  4. String2Timestamp(String s, String fmt)
  5. string2Timestamp(String strDateTime, String pattern)
  6. string2Timestamp(String value)
  7. stringToTimestamp()
  8. stringToTimestamp(final String dateString)
  9. stringToTimestamp(String aS_Timestamp, String aS_Format, Timestamp aTs_ValidStart, Timestamp aTs_ValidEnd)