Converts dates to strings using the same format specifiers as strftime Notes: This does not mimic strftime perfectly. Certain strftime commands, are not supported, and will convert as if they were literals. Certain complicated commands, like those dealing with the week of the year
| 36 | * </ul> |
| 37 | */ |
| 38 | public class Strftime { |
| 39 | /** |
| 40 | * Mapping of strftime format specifiers to SimpleDateFormat equivalents. |
| 41 | */ |
| 42 | protected static final Properties translate; |
| 43 | |
| 44 | /** |
| 45 | * The underlying SimpleDateFormat instance used for date formatting. |
| 46 | */ |
| 47 | protected final SimpleDateFormat simpleDateFormat; |
| 48 | |
| 49 | /* |
| 50 | * Initialize our pattern translation |
| 51 | */ |
| 52 | static { |
| 53 | translate = new Properties(); |
| 54 | translate.put("a", "EEE"); |
| 55 | translate.put("A", "EEEE"); |
| 56 | translate.put("b", "MMM"); |
| 57 | translate.put("B", "MMMM"); |
| 58 | translate.put("c", "EEE MMM d HH:mm:ss yyyy"); |
| 59 | |
| 60 | // There's no way to specify the century in SimpleDateFormat. We don't want to hard-code |
| 61 | // 20 since this could be wrong for the pre-2000 files. |
| 62 | // translate.put("C", "20"); |
| 63 | translate.put("d", "dd"); |
| 64 | translate.put("D", "MM/dd/yy"); |
| 65 | translate.put("e", "dd"); // will show as '03' instead of ' 3' |
| 66 | translate.put("F", "yyyy-MM-dd"); |
| 67 | translate.put("g", "yy"); |
| 68 | translate.put("G", "yyyy"); |
| 69 | translate.put("H", "HH"); |
| 70 | translate.put("h", "MMM"); |
| 71 | translate.put("I", "hh"); |
| 72 | translate.put("j", "DDD"); |
| 73 | translate.put("k", "HH"); // will show as '07' instead of ' 7' |
| 74 | translate.put("l", "hh"); // will show as '07' instead of ' 7' |
| 75 | translate.put("m", "MM"); |
| 76 | translate.put("M", "mm"); |
| 77 | translate.put("n", "\n"); |
| 78 | translate.put("p", "a"); |
| 79 | translate.put("P", "a"); // will show as pm instead of PM |
| 80 | translate.put("r", "hh:mm:ss a"); |
| 81 | translate.put("R", "HH:mm"); |
| 82 | // There's no way to specify this with SimpleDateFormat |
| 83 | // translate.put("s","seconds since epoch"); |
| 84 | translate.put("S", "ss"); |
| 85 | translate.put("t", "\t"); |
| 86 | translate.put("T", "HH:mm:ss"); |
| 87 | // There's no way to specify this with SimpleDateFormat |
| 88 | // translate.put("u","day of week ( 1-7 )"); |
| 89 | |
| 90 | // There's no way to specify this with SimpleDateFormat |
| 91 | // translate.put("U","week in year with first Sunday as first day..."); |
| 92 | |
| 93 | translate.put("V", "ww"); // I'm not sure this is always exactly the same |
| 94 | |
| 95 | // There's no way to specify this with SimpleDateFormat |