Java tutorial
//package com.java2s; import java.io.File; import android.text.format.DateFormat; import android.text.format.DateUtils; public class Main { public static String getDateFromName(String fName) { if (fName == null) return fName; String name = extractDateFromFName(fName); // output as time or date CharSequence df; long millis = Long.parseLong(name); if (DateUtils.isToday(millis)) { df = "'today' hh:mmaa"; } else { df = "dd MMM hh:mmaa"; } return (String) DateFormat.format(df, millis); } public static String extractDateFromFName(String fName) { if (fName == null) return fName; // get basename String name = new File(fName).getName(); // cut extension return removeExtension(name); } public static String removeExtension(String s) { String separator = System.getProperty("file.separator"); String filename; // Remove the path up to the filename. int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex == -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1); } // Remove the extension. int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) return filename; return filename.substring(0, extensionIndex); } }