Java SQL Date From toDateFromString(String str)

Here you can find the source of toDateFromString(String str)

Description

to Date From String

License

Open Source License

Declaration

public static Date toDateFromString(String str) 

Method Source Code

//package com.java2s;
/**//from w  w w . j av a  2s  . com
 * JWatch - Quartz Monitor: http://code.google.com/p/jwatch/
 * Copyright (C) 2011 Roy Russo and the original author or authors.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 **/

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

public class Main {
    public static final String DATE_FORMAT_DEFAULT = "yyyy-MM-dd HH:mm:ss";

    public static Date toDateFromString(String str) {
        DateFormat format = new SimpleDateFormat(DATE_FORMAT_DEFAULT);
        Date date = null;
        try {
            // Fri Feb 24 00:00:00 CST 2012
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // 2012-02-24
        // date = java.sql.Date.valueOf(str);

        return date;
    }
}

Related

  1. toDate(Object o)
  2. toDate(Object obj)
  3. toDate(Object value)
  4. toDate(String dateString)
  5. toDate(String s)
  6. toDateMidnight(java.util.Date d)
  7. toDateStr(java.util.Date d)
  8. toSqlDate(Calendar calendar)
  9. toSqlDate(Date date)