Java Date Parse getDateFromFileName(String fileName)

Here you can find the source of getDateFromFileName(String fileName)

Description

get Date From File Name

License

Apache License

Declaration

public static Date getDateFromFileName(String fileName) 

Method Source Code

//package com.java2s;
/**/*from   w  ww. j av  a2 s . c  o m*/
 * Sahi - Web Automation and Test Tool
 *
 * Copyright  2006  V Narayan Raman
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date getDateFromFileName(String fileName) {
        int start = fileName.lastIndexOf("__");
        int length = fileName.length();
        if (start != -1)
            start = fileName.lastIndexOf("__", start - 1);
        int end = fileName.lastIndexOf(".");
        start = (start == -1) ? 0 : start + 2;
        if (end == -1)
            end = length;
        String dateString = fileName.substring(start, end);
        try {
            return new SimpleDateFormat("ddMMMyyyy__HH_mm_ss").parse(dateString);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. getDateFromCurrentAnd24HRTime(Date current, String hr24Time)
  2. getDateFromDateAge(Date currentDate, String age)
  3. getDateFromDatestamp(String datestamp)
  4. getDateFromDateTimeUTCFormat(final String dateString)
  5. getDateFromDCItemTimestamp(String dateTimeStamp)
  6. getDateFromFormat(Date date, String type)
  7. getDateFromFormattedDate(String dateStr, String format)
  8. getDateFromFormattedTimeStamp( String formattedTimeStamp)
  9. getDateFromIRODSValue(final String irodsValue)