Java Date from String getDateFromString(String strDate, String strTime)

Here you can find the source of getDateFromString(String strDate, String strTime)

Description

get Date From String

License

Open Source License

Declaration

public static Date getDateFromString(String strDate, String strTime) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getDateFromString(String strDate, String strTime) {
        Calendar cal = Calendar.getInstance();

        String[] arrDate = strDate.split("-");
        String[] arrTime = strTime.split("[:-]");

        cal.set(Integer.parseInt(arrDate[0]), Integer.parseInt(arrDate[1]) - 1, Integer.parseInt(arrDate[2]),
                Integer.parseInt(arrTime[0]), Integer.parseInt(arrTime[1]), Integer.parseInt(arrTime[1]));

        return cal.getTime();
    }/* w w  w  . j a  v a 2s  .c  o  m*/

    public static Date getDateFromString(String dateString) {
        Date ret = null;

        String[] tmp = dateString.split("-");
        if (tmp.length == 3) {
            Calendar c = Calendar.getInstance();
            c.set(Integer.parseInt(tmp[0]), Integer.parseInt(tmp[1]) - 1, Integer.parseInt(tmp[2]), 0, 0, 0);
            ret = c.getTime();
        }

        return ret;
    }
}

Related

  1. convertToDateWithTimeString(Date date)
  2. getDateFromPattern(String pattern)
  3. getDateFromReccurenceInterval(int reqDOW, int reqDOM, int time)
  4. getDateFromStartTime(String startTime)
  5. getDateFromString(String s)
  6. getDateFromString(String stringDate)
  7. getDateFromTime(long millisSinceMidnight)