Java String to Date stringToDate(String dateString, String dateFormat)

Here you can find the source of stringToDate(String dateString, String dateFormat)

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String dateString, String dateFormat) 

Method Source Code


//package com.java2s;
/*/*from ww  w. j  a  va  2s.  c om*/
 * Title:      TRS ??????
 * Copyright: Copyright (c) 2004-2005, TRS?????????????. All rights reserved.
 * License:   see the license file.
 * Company:   TRS?????????????(www.trs.com.cn)
 * 
 * Created on 2005-5-11
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date stringToDate(String dateString, String dateFormat) {
        if ("".equals(dateString) || dateString == null) {
            return null;
        }
        try {
            return new SimpleDateFormat(dateFormat).parse(dateString);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. stringToDate(String dateString)
  2. stringToDate(String dateString)
  3. stringToDate(String dateString)
  4. stringToDate(String dateString)
  5. stringToDate(String dateString, String dataFormat)
  6. stringTodate(String dateString, String format)
  7. stringToDate(String dateString, String formatStr)
  8. stringToDate(String dateString, String pattern)
  9. stringToDate(String dateText, String format, boolean lenient)