Java String to Time getTime(String time)

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

Description

get Time

License

Apache License

Declaration

public static Date getTime(String time) 

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 final String DEFAULT_FORMAT_TIME = "HH:mm:ss";
    public static final String DEFAULT_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";

    public static Date getTime(String time) {
        return getDateTime(time, DEFAULT_FORMAT_TIME);
    }/*w  w w.j a va 2  s .  c  o m*/

    public static Date getDateTime(String dateString, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = sf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDateTime(String dateTimeString) {
        return getDateTime(dateTimeString, DEFAULT_FORMAT_DATETIME);
    }
}

Related

  1. getTime(String parrten)
  2. getTime(String pattern)
  3. getTime(String pattern)
  4. getTime(String s)
  5. getTime(String sDateTime, String eDateTime)
  6. getTime(String time)
  7. getTimeDate(String time)
  8. getTimes(String startTime, String endTime)
  9. replaceDateTime(String input)