Java String to Time string2DateTimeByAutoZero(String stringDate)

Here you can find the source of string2DateTimeByAutoZero(String stringDate)

Description

string Date Time By Auto Zero

License

Open Source License

Declaration

public static final Date string2DateTimeByAutoZero(String stringDate) throws ParseException 

Method Source Code


//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss";

    public static final Date string2DateTimeByAutoZero(String stringDate) throws ParseException {
        if (stringDate == null) {
            return null;
        }//from   w w w. j av  a 2s . co  m
        if (stringDate.length() == 11)
            stringDate = stringDate + "00:00:00";
        else if (stringDate.length() == 13)
            stringDate = stringDate + ":00:00";
        else if (stringDate.length() == 16)
            stringDate = stringDate + ":00";
        else if (stringDate.length() == 10)
            stringDate = stringDate + " 00:00:00";

        return getFormat(datetimeFormat).parse(stringDate);
    }

    public static final DateFormat getFormat(String format) {
        return new SimpleDateFormat(format);
    }
}

Related

  1. getTimes(String startTime, String endTime)
  2. replaceDateTime(String input)
  3. str2DateTime(String strDate)
  4. string2Date(String time)
  5. string2DateTime(String stringDate)
  6. stringToCalendar(String stringTime)
  7. stringToCalendar(String timeStr)
  8. stringToTimeDate(String timeStr)
  9. toTime(final String dateString)