/** * Format an Unix timestamp to a string suitable for display to the user according to their system * settings (12 or 24 hour time). * * @param Context context - The context of the calling activity. * @param long timestamp - The human unfriendly timestamp. * @return String */ public static String formatTimestamp(Context context, long timestamp) { String HOURS_24 = "24"; String hours = "24"; SimpleDateFormat mSDF = new SimpleDateFormat(); if (HOURS_24.equals(hours)) { mSDF.applyLocalizedPattern(TIME_FORMAT_24_HOUR); } else { mSDF.applyLocalizedPattern(TIME_FORMAT_12_HOUR); } return mSDF.format(new Date(timestamp)); }
void testApplyPatternAndApplyLocalizedPatternWithConstantPattern() { SimpleDateFormat sdf = new SimpleDateFormat(); // BUG: Diagnostic contains: sdf.applyPattern(WEEK_YEAR_PATTERN); // BUG: Diagnostic contains: sdf.applyLocalizedPattern(WEEK_YEAR_PATTERN); }
void testApplyPatternAndApplyLocalizedPatternWithLiteralPattern() { SimpleDateFormat sdf = new SimpleDateFormat(); // BUG: Diagnostic contains: sdf.applyPattern("yyyy-MM-dd") sdf.applyPattern("YYYY-MM-dd"); // BUG: Diagnostic contains: sdf.applyLocalizedPattern("yyyy-MM-dd") sdf.applyLocalizedPattern("YYYY-MM-dd"); }