Java String to Date stringToDate(String strDate)

Here you can find the source of stringToDate(String strDate)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String strDate) throws ParseException 

Method Source Code


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

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

public class Main {
    private static final String PATTERN = "yyyyMMdd";
    public static final String PATTERN_TIME4 = "yyyyMMddHHmm";

    public static Date stringToDate(String strDate) throws ParseException {
        DateFormat df = new SimpleDateFormat(PATTERN);
        Date date = df.parse(strDate);
        return date;
    }// w  w w .  j a v  a2s  .c o m

    public static Date stringToDate(String strDate, String pattern) throws ParseException {
        DateFormat df = new SimpleDateFormat(pattern);
        Date date = df.parse(strDate);
        return date;
    }

    public static Calendar StringtoDate(String sb) throws ParseException {

        DateFormat df = new SimpleDateFormat(PATTERN_TIME4);
        Date date = df.parse(sb);
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(date.getTime());
        return cal;

    }
}

Related

  1. StringToDate(String str)
  2. StringToDate(String str, String format)
  3. stringToDate(String str, String format)
  4. stringToDate(String str, String formatStr)
  5. stringToDate(String strDate)
  6. stringToDate(String strDate)
  7. stringToDate(String strDate)
  8. stringToDate(String strDate, String formartStr)
  9. stringToDate(String strDate, String oracleFormat)