Java Timestamp isTimestamp(String aS_DateTime, String aS_Format)

Here you can find the source of isTimestamp(String aS_DateTime, String aS_Format)

Description

Checks if datetime is aS_DateTime is same as in aS_Format

License

Open Source License

Parameter

Parameter Description
aS_DateTime String containing datetime
aS_Format String containing datetime format

Return

true if ok false if error. Null values = error

Declaration


public static boolean isTimestamp(String aS_DateTime, String aS_Format) 

Method Source Code

//package com.java2s;
/*/*  w  ww. j a  v  a2  s .  co  m*/
NetForm Library
---------------
Copyright (C) 2001-2005 - Sampsa Sohlman, Teemu Sohlman
    
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 2.1 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
*/

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    /**
     * Checks if datetime is aS_DateTime is same as in aS_Format
     * @param aS_DateTime String containing datetime
     * @param aS_Format String containing datetime format
     * @return true if ok false if error. Null values = error
     */

    public static boolean isTimestamp(String aS_DateTime, String aS_Format) {
        return stringToTimestamp(aS_DateTime, aS_Format, null, null) != null;
    }

    /**
     * Converts string to java.sql.Timestamp using format string
     * @param aS_Timestamp String containing timestamp
     * @param aS_Format String containing timestamp format
     * @return java.sql.Timestamp object if ok, else null
     * @see java.text.SimpleDateFormat for format options
     */
    public static java.sql.Timestamp stringToTimestamp(String aS_Timestamp, String aS_Format,
            Timestamp aTs_ValidStart, Timestamp aTs_ValidEnd) {
        SimpleDateFormat l_SimpleDateFormat;
        java.sql.Timestamp l_Timestamp;
        java.util.Date l_Date = null;

        if (aS_Timestamp == null || aS_Format == null) {
            return null;
        }

        l_SimpleDateFormat = new SimpleDateFormat(aS_Format);
        try {
            l_Date = l_SimpleDateFormat.parse(aS_Timestamp);
            l_Timestamp = new java.sql.Timestamp(l_Date.getTime());

            if (aTs_ValidStart == null || aTs_ValidEnd == null) {
                return l_Timestamp;
            }

            if (aTs_ValidStart.before(l_Timestamp) && aTs_ValidEnd.after(l_Timestamp)) {
                return l_Timestamp;
            } else {
                return null;
            }
        } catch (ParseException a_ParseException) {
            return null;
        }
    }

    public static java.sql.Timestamp stringToTimestamp(String aS_Timestamp, String aS_Format) {
        return stringToTimestamp(aS_Timestamp, aS_Format, null, null);

    }
}

Related

  1. isLongTerm(Timestamp oldTime, Timestamp newTime)
  2. isSameDay(Timestamp one, Timestamp two)
  3. isSameMonth(Timestamp t1, Timestamp t2)
  4. IsTechStatisticWorkTime(Timestamp timestamp)
  5. isTimeStamp(Class o)
  6. isTimestamp(String str)
  7. isValid(Timestamp validFrom, Timestamp validTo, Timestamp testDate)
  8. long2Timestamp(Long longValue)
  9. longFromTimestamp(Timestamp ts)