Java Timestamp strToTimestamp(String i_Today, String i_Hour, String i_Minute)

Here you can find the source of strToTimestamp(String i_Today, String i_Hour, String i_Minute)

Description

str To Timestamp

License

Open Source License

Declaration

public static Timestamp strToTimestamp(String i_Today, String i_Hour, String i_Minute) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.*;
import java.text.*;

public class Main {
    public static final SimpleDateFormat SDF_FULL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Timestamp strToTimestamp(String i_Today, String i_Hour, String i_Minute) {
        try {/*from w  ww  .  ja va2s .  com*/
            if (i_Today == null || i_Hour == null || i_Minute == null) {
                return null;
            }

            java.util.Date d = strToDate(i_Today, i_Hour, i_Minute);
            return new java.sql.Timestamp(d.getTime());
        } catch (Exception e) {
            // e.printStackTrace();
        }

        return null;
    }

    public static Timestamp strToTimestamp(String i_StrDate) {
        try {
            if (i_StrDate == null || "".equals(i_StrDate)) {
                return null;
            }

            java.util.Date v_Date = strToDate(i_StrDate);
            return new java.sql.Timestamp(v_Date.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public static java.util.Date strToDate(String i_Today, String i_Hour, String i_Minute) {
        try {
            if (i_Today == null || i_Hour == null || i_Minute == null) {
                return null;
            }

            return SDF_FULL.parse(i_Today.trim() + " " + i_Hour.trim() + ":" + i_Minute.trim() + ":00");
        } catch (Exception e) {
            // e.printStackTrace();
        }

        return null;
    }

    public static java.util.Date strToDate(String i_StrDate) {
        try {
            if (i_StrDate == null || "".equals(i_StrDate.trim())) {
                return null;
            }

            return SDF_FULL.parse(i_StrDate);
        } catch (Exception e) {
            // e.printStackTrace();
        }

        return null;
    }

    public static java.util.Date strToDate(String i_StrDate, String i_Format) throws ParseException {
        SimpleDateFormat SDF_My = new SimpleDateFormat(i_Format);

        try {
            return SDF_My.parse(i_StrDate);
        } catch (ParseException e) {
            throw e;
        }
    }

    public static java.util.Date strToDate(String i_StrDate, SimpleDateFormat i_SDF) throws ParseException {
        try {
            return i_SDF.parse(i_StrDate);
        } catch (ParseException e) {
            throw e;
        }
    }
}

Related

  1. SQLTimestampToDate(java.sql.Timestamp ts)
  2. sqlTimestampToDate(Timestamp t)
  3. StrToDateTimeFormat(String timestampStr,String pattern)
  4. strToTimestamp(String date)
  5. strToTimestamp(String dateStr)
  6. StrToTimestamp(String timestampStr,String pattern)
  7. timestamp()
  8. timestamp(int year, int month, int day, int hour, int minute, int second, int nanosecond)
  9. timestamp(Long param)