Java String to Date timeToDate(String time)

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

Description

time To Date

License

Open Source License

Parameter

Parameter Description

Return

Retorna un dato de tipo Date

Declaration

public static Date timeToDate(String time) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*w w  w . j a  v a2 s .c om*/
     *
     * @param time: LA hora en formato HH:mm o HH:mm:ss
     * @return Retorna un dato de tipo Date
     */
    public static Date timeToDate(String time) {
        Date fecha = null;
        try {
            SimpleDateFormat sdf;
            if (time.length() == 5) {
                sdf = new SimpleDateFormat("HH:mm");
            } else if (time.length() == 8) {
                sdf = new SimpleDateFormat("HH:mm:ss");
            } else {
                throw new RuntimeException("Formato de tiempo incorrecto.");
            }
            fecha = sdf.parse(time);
        } catch (Exception e) {
        }
        return fecha;
    }
}

Related

  1. strToDateM6(String StrToDate)
  2. StrToDateSeco(String str)
  3. strToDatetime(String sStr)
  4. strToDateWithFormat(String strDate, Format format)
  5. TimeStringToDate(String s)
  6. toDate(DateFormat format, String value)
  7. toDate(final Long date, final String pattern)
  8. toDate(final String _text, final String _dateFormat)
  9. toDate(final String date, final String time)