Here you can find the source of dateFromFilename(File file, Pattern fileNamePattern, DateFormat dateFormat)
Parameter | Description |
---|---|
fileNamePattern | The pattern that the file must match. It's first group should be the date portion of the file name. |
dateFormat | The format used to parse the date portion of the file name. |
public static long dateFromFilename(File file, Pattern fileNamePattern, DateFormat dateFormat)
//package com.java2s; import java.io.File; import java.text.DateFormat; import java.text.ParsePosition; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**/*from w w w.ja v a 2 s . c o m*/ * Returns the date embedded in the given file name as milliseconds since * the epoch. Returns zero if the file does not match the given * {@code fileNamePattern}. * * @param fileNamePattern * The pattern that the file must match. It's first group should * be the date portion of the file name. * @param dateFormat * The format used to parse the date portion of the file name. */ public static long dateFromFilename(File file, Pattern fileNamePattern, DateFormat dateFormat) { long utc = 0; Matcher m = fileNamePattern.matcher(file.getName()); if (m.matches()) { utc = dateFormat.parse(m.group(1), new ParsePosition(0)).getTime(); } return utc; } }