Android Date String Parse stringConvertDate(String date)

Here you can find the source of stringConvertDate(String date)

Description

string Convert Date

Declaration

public static Date stringConvertDate(String date) 

Method Source Code

//package com.java2s;

import java.sql.Timestamp;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date stringConvertDate(String date) {
        if (null == date || "".equals(date)) {
            return null;
        }/* ww  w.j  a va2  s . c  o  m*/
        if (date.length() == 10) {// yyyy-MM-dd
            date = date + " 00:00:00";
        } else if (date.length() == 16) {// yyyy-MM-dd hh:mm
            date = date + ":00";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        Date objDate;
        try {
            objDate = formatter.parse(date);
        } catch (ParseException e) {
            objDate = null;
        }
        return objDate;
    }

    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. parse(String input)
  2. parse(String source, String pattern)
  3. parseDate(String value, String[] parsePatterns)
  4. parseJsonDate(String jsonDate)
  5. str2Date(String str)
  6. stringToDate(String date)
  7. toDate(String string)
  8. tokenizeDate(String date)
  9. String2Date(String dateStr)