List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:Main.java
public static String getPrettyDateTime(Calendar date) { DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); return dateTimeFormat.format(date.getTime()); }
From source file:Main.java
public static CharSequence getSameDayTime(Long time) { return DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT, DateFormat.SHORT); }
From source file:Main.java
public static String dateFormatShort(Date date) { DateFormat dateFormat1 = DateFormat.getDateInstance(DateFormat.SHORT); return dateFormat1.format(date); }
From source file:Main.java
public static String calendarDateForLocale(Calendar calendar, Locale locale) { DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); return dateFormatter.format(calendar.getTime()); }
From source file:Main.java
private static String setDate(int day, Locale locale) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, +day); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); if (df instanceof SimpleDateFormat) { SimpleDateFormat sdf = (SimpleDateFormat) df; // To show Locale specific short date expression with full year String pattern = sdf.toPattern().replaceAll("y+", "yyyy"); sdf.applyPattern(pattern);//from w ww.java2 s .c o m return sdf.format(cal.getTime()); } String formattedDate = df.format(cal.getTime()); return formattedDate; }
From source file:Main.java
public static DateFormat getDateFormat(final boolean seconds) { return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, seconds ? DateFormat.MEDIUM : DateFormat.SHORT); }
From source file:Main.java
/** * Formats date//w ww.j a v a 2 s . co m * * @param time Time to format * @param locale Locale * @return Formatted string */ public static String formatDateTime(Date time, Locale locale) { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale); return dateFormat.format(time); }
From source file:Main.java
public static void printDate(Locale locale, Date date) { DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); String formattedDate = formatter.format(date); System.out.println("SHORT: " + formattedDate); formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); formattedDate = formatter.format(date); System.out.println("MEDIUM: " + formattedDate + "\n"); }
From source file:Main.java
public static String DateMessage(Date d, Context c) { DateFormat df = DateFormat.getDateTimeInstance(); DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); DateFormat dfNoTime = DateFormat.getDateInstance(); DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH); DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH); DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH); DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c); String s = dfDevice.format(d) + " or \n" + dfS.format(d) + " or \n" + dfM.format(d) + " or \n" + dfL.format(d) + " or \n" + dfF.format(d); return s;/*from w w w. ja v a 2 s . c om*/ }
From source file:Main.java
public static Date FormatDate(String sRecDate, Context c) { DateFormat df = DateFormat.getDateTimeInstance(); DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); DateFormat dfNoTime = DateFormat.getDateInstance(); DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH); DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH); DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH); DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c); Date dRecDate = null;//www . ja v a 2 s . c o m try { dRecDate = dfDevice.parse(sRecDate); } catch (ParseException e) { try { dRecDate = df.parse(sRecDate); } catch (ParseException e2) { try { dRecDate = dfS.parse(sRecDate); } catch (ParseException e3) { try { dRecDate = dfM.parse(sRecDate); } catch (ParseException e4) { try { dRecDate = dfL.parse(sRecDate); } catch (ParseException e5) { try { dRecDate = dfF.parse(sRecDate); } catch (ParseException e6) { try { dRecDate = dfNoTime.parse(sRecDate); } catch (ParseException e7) { try { dRecDate = dfSNoTime.parse(sRecDate); } catch (ParseException e8) { try { dRecDate = dfMNoTime.parse(sRecDate); } catch (ParseException e9) { try { dRecDate = dfLNoTime.parse(sRecDate); } catch (ParseException e10) { try { dRecDate = dfFNoTime.parse(sRecDate); } catch (ParseException e11) { } } } } } } } } } } } return dRecDate; }