Java String to Date toDateByFormat(String dateString, String formatStr)

Here you can find the source of toDateByFormat(String dateString, String formatStr)

Description

to Date By Format

License

Apache License

Declaration

public static Date toDateByFormat(String dateString, String formatStr) 

Method Source Code

//package com.java2s;
/*/*from  www .  jav a 2s  .co  m*/
 * BJAF - Beetle J2EE Application Framework
 * ???J2EE???????????
 * ??????2003-2015 ??? (www.beetlesoft.net)
 * 
 * ??????????????????
 *<http://www.apache.org/licenses/LICENSE-2.0>
 *????????????????????????
 *
 * ???????????????????????????????
 * ??? <yuhaodong@gmail.com/>.
 */

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

public class Main {
    public static Date toDateByFormat(String dateString, String formatStr) {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(formatStr);
        try {
            return sdf.parse(dateString);
        } catch (ParseException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

  1. toDate(String string, String format)
  2. toDate(String time)
  3. toDate(String time)
  4. toDate(String ts)
  5. toDate(String value)
  6. toDateByPattern(String dateTime)
  7. toDateFormat(Integer grain, TimeZone timeZone, String dateFormatArg)
  8. toDateFormat(String date)
  9. toDateFormat(String dateFormat, TimeZone tz, Locale locale)