Java String to Date toDate(String param)

Here you can find the source of toDate(String param)

Description

to Date

License

Apache License

Declaration

public static Date toDate(String param) 

Method Source Code

//package com.java2s;
/**/* ww w. j av a  2 s. c o  m*/
 * Tern Framework.
 * 
 * @author fancimage
 * @Copyright 2010 qiao_xf@163.com Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

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

public class Main {
    public static Date toDate(String param) {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(param);
        } catch (ParseException ex) {
        }
        return date;
    }

    public static Date toDate(String param, String pattern) {
        if (param == null)
            return null;
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            date = sdf.parse(param);
        } catch (ParseException ex) {
        }
        return date;
    }
}

Related

  1. toDate(String dateToConvert)
  2. toDate(String dateToDatify)
  3. toDate(String dateValue, String format)
  4. toDate(String format, String str)
  5. toDate(String formatDate, String stringDate)
  6. toDate(String patten, String value)
  7. toDate(String pattern, String date)
  8. toDate(String pString, String pFormat)
  9. toDate(String s)