Java String to Time getTimeDate(String time)

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

Description

get Time Date

License

Apache License

Declaration

public static Date getTimeDate(String time) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Date getTimeDate(String time) {
        // format "yyyy-MM-dd HH:mm:00"
        String string = sdf.format(getCurrentDateTime());
        string += " " + time;
        Date date = null;/*from  w  w  w .j  ava2 s.  c om*/
        try {
            date = sdf2.parse(string);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static String format(Date date) {
        return sdf2.format(date);
    }

    /**
     * Gets the current date time.
     * 
     * @return the current date time
     */
    public static Date getCurrentDateTime() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime();
    }
}

Related

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