Here you can find the source of getDateFromFileName(String fileName)
public static Date getDateFromFileName(String fileName)
//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; } } }