Java SQL Time isDateTime(String val)

Here you can find the source of isDateTime(String val)

Description

is Date Time

License

Open Source License

Declaration

private static boolean isDateTime(String val) 

Method Source Code


//package com.java2s;
/*//from ww  w. j  a v  a2  s.  c o  m
 * @(#)SQLUtil.java $Date: Dec 16, 2011 6:28:55 PM $
 * 
 * Copyright ? 2011 FortMoon Consulting, Inc. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of FortMoon
 * Consulting, Inc. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with FortMoon Consulting.
 * 
 * FORTMOON MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. FORTMOON SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 * 
 */

import java.sql.Date;

public class Main {
    private static boolean isDateTime(String val) {
        if (val != null) {
            String str[] = val.split("\\s");
            if (str.length == 2 && isDate(str[0]) && isTime(str[1]))
                return true;
        }
        return false;
    }

    /**
     * @param val
     * @return
     */
    private static boolean isDate(String val) {
        try {
            Date.valueOf(val);
            return true;
        } catch (IllegalArgumentException ie) {
        }
        return false;
    }

    private static boolean isTime(String val) {
        try {
            if (null != java.sql.Time.valueOf(val))
                return true;
        } catch (IllegalArgumentException iae) {

        }
        return false;
    }
}

Related

  1. getSQLDateTime()
  2. getZeroTimeDate(Date fecha)
  3. isBetweenHours(Time hora, Time horaInicio, Time horaFim)
  4. isCategoryDateOrTime(String sJavaType)
  5. isDateTime(int type)
  6. isTime(final Class type)
  7. isTime(final PropertyDescriptor pd)
  8. isTime(String val)
  9. isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d)