Java String to Date toDate(final String date, final String time)

Here you can find the source of toDate(final String date, final String time)

Description

to Date

License

Apache License

Parameter

Parameter Description
date date string as yyyy-MM-dd
time time string as HH:mm

Return

Date representation

Declaration

public static Date toDate(final String date, final 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 {
    /**/*from   w  ww  . j  a  v a 2  s.  c  o m*/
     * @param date date string as yyyy-MM-dd
     * @return Date representation
     */
    public static Date toDate(final String date) {
        return toDate(date, "00:00.00.000");
    }

    /**
     * @param date date string as yyyy-MM-dd
     * @param time time string as HH:mm
     * @return Date representation
     */
    public static Date toDate(final String date, final String time) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date + " " + time);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. TimeStringToDate(String s)
  2. timeToDate(String time)
  3. toDate(DateFormat format, String value)
  4. toDate(final Long date, final String pattern)
  5. toDate(final String _text, final String _dateFormat)
  6. toDate(final String dateString, final String format)
  7. toDate(final String dateString, final String pattern)
  8. toDate(int date, String timeFormat)
  9. toDate(long value, String format)