Android Timestamp String to Timestamp Convert stringConvertTimestamp(String time)

Here you can find the source of stringConvertTimestamp(String time)

Description

string Convert Timestamp

Declaration

public static Timestamp stringConvertTimestamp(String time) 

Method Source Code

//package com.java2s;

import java.sql.Timestamp;

public class Main {
    public static Timestamp stringConvertTimestamp(String time) {
        if (null == time || "".equals(time)) {
            return null;
        }//from w  w w.  jav a  2s . com
        if (time.length() == 10) {// yyyy-MM-dd
            time = time + " 00:00:00.000000000";
        } else if (time.length() == 16) {// yyyy-MM-dd hh:mm
            time = time + ":00.000000000";
        } else if (time.length() == 19) {// yyyy-MM-dd hh:mm:dd
            time = time + ".000000000";
        }
        return Timestamp.valueOf(time);
    }

    public static boolean equals(Timestamp t1, Timestamp t2) {
        if (t1 == null && t2 == null) {
            return true;
        } else {
            if (t1 == null) {
                return t2.equals(t1);
            } else {
                return t1.equals(t2);
            }
        }
    }
}

Related

  1. str2Timestamp(String str)
  2. serverTimestampToDate(String timestamp)