Java SQL Date Create createSqlDate(String dateStr)

Here you can find the source of createSqlDate(String dateStr)

Description

create Sql Date

License

Apache License

Declaration

public static java.sql.Date createSqlDate(String dateStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat df[] = { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"),
            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"),
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss.SSS'Z'"),
            new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss.SSSZ"), new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss.SSS"),
            new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ssZ"), new SimpleDateFormat("MM/dd/yyyy'T'HH:mm:ss"),
            new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"), new SimpleDateFormat("MM/dd/yyyy HH:mm"),
            new SimpleDateFormat("MM/dd/yyyy"), new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"),
            new SimpleDateFormat("yyyyMMdd") };

    public static java.sql.Date createSqlDate(String dateStr) {
        Date date = createDate(dateStr);
        if (date != null) {
            return new java.sql.Date(date.getTime());
        }// w  ww.  j a  v  a 2 s  .  c o  m

        return null;
    }

    public static Date createDate(String dateStr) {
        Date returnDate;
        for (int i = 0; i < df.length; i++) {
            try {
                returnDate = df[i].parse(dateStr);
                return returnDate;
            } catch (Exception ex) {
                // Try next one...
            }
        }

        return null;
    }
}

Related

  1. convertToUDate(String dateInString)
  2. createDate(int day, int month, int year)
  3. createDateFormater(int dataType)
  4. createFutureDate(java.sql.Date lmpDate, int offSet)
  5. createRecGetStatementsUpdate(String tip, String imeFirstCap)
  6. createStreamingStatement(Connection conn, boolean update)
  7. createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)
  8. currentDate()
  9. currentDate()