Java Date Format Check checkDateFormat(String strTime, String pattern)

Here you can find the source of checkDateFormat(String strTime, String pattern)

Description

check Date Format

License

Open Source License

Declaration

public static boolean checkDateFormat(String strTime, String pattern) 

Method Source Code

//package com.java2s;
/**//  w w w . j  a v  a  2  s  .co m
 * ============================================================================== Copyright (c) 2015 by www.tencent.com,
 * All rights reserved. ============================================================================== This software is
 * the confidential and proprietary information of tencent.com, 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 tencent.com, Inc.
 * ------------------------------------------------------------------------------
 * <p/>
 * Author: faberxu Date: 2015/12/18 Description: Nothing. Function List: 1. Nothing. History: 1. Nothing.
 * ==============================================================================
 */

import java.text.SimpleDateFormat;

public class Main {

    public static boolean checkDateFormat(String strTime, String pattern) {
        if (strTime.length() != pattern.trim().length())
            return false;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern.trim());
            sdf.parse(strTime);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}

Related

  1. checkDateBetween(String time)
  2. checkDateByMask(String sDateValue, String sDateFormat)
  3. checkDateFormat()
  4. checkDateFormat()
  5. checkDateFormat(String pattern)
  6. checkDateFormatAndValite(String strDateTime, String format)
  7. checkDateInToday(Date date)
  8. checkDateRange(String fromDate, String endDate)
  9. checkDateValidity(String str, String formatString)