Java String to Time stringToTimeDate(String timeStr)

Here you can find the source of stringToTimeDate(String timeStr)

Description

string To Time Date

License

Open Source License

Declaration

public static Date stringToTimeDate(String timeStr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final String FORMATO_HORA = "HH:mm";
    private static final String EPOCH = "01/01/1970";

    public static Date stringToTimeDate(String timeStr) {
        return formatStrToDate(FORMATO_HORA, timeStr);
    }/*  w w w  . j  a  v  a2 s  .c om*/

    private static Date formatStrToDate(String format, String dateStr) {
        if (dateStr.trim().equals("")) {
            dateStr = EPOCH;
        }
        try {
            SimpleDateFormat curFormater = new SimpleDateFormat(format);
            return curFormater.parse(dateStr);
        } catch (ParseException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

  1. string2Date(String time)
  2. string2DateTime(String stringDate)
  3. string2DateTimeByAutoZero(String stringDate)
  4. stringToCalendar(String stringTime)
  5. stringToCalendar(String timeStr)
  6. toTime(final String dateString)
  7. toTime(String display)
  8. toTime(String str)