Java Time Parse isDateTime(String dateTime)

Here you can find the source of isDateTime(String dateTime)

Description

is Date Time

License

Apache License

Declaration

public static boolean isDateTime(String dateTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static boolean isDateTime(String dateTime) {
        int first = dateTime.indexOf(":");
        int last = dateTime.lastIndexOf(":");
        if (first == -1) {
            return false;
        }/*from w w  w.  ja v a  2s  .c  om*/
        SimpleDateFormat df = null;
        if (first == last) {
            df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        } else {
            df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        }
        Date date = null;
        try {
            date = df.parse(dateTime);
        } catch (ParseException e) {
            return false;
        }
        return date == null;
    }
}

Related

  1. getTimeFromString(String time)
  2. getTimeList(String start, String end, int pitch)
  3. getTimeStr(String date1, String date2)
  4. getTimeWithStr(String source, String pattern)
  5. getTimeX(String dateStr)
  6. isDateTime(String dateTime, String pattern)
  7. isDatetimeParsable(String value)
  8. isFromartDate(String time)
  9. isTime(final String date)