@Test public void testTimeZone() throws Exception { long time = new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-05").getTime(); FastDateFormat cal = new FastDateFormat(TimeZone.getTimeZone("GMT+5"), Locale.ENGLISH); assertEquals("+05:00", cal.getDate(time, FastDateFormat.XXX)); }
public String getDate(long now, String pattern) { sameDay(now); String date = cache.get(pattern); if (date == null) { if (MMM_D2.equals(pattern)) { StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.Field.DAY_OF_MONTH); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd", locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); sdf.format(new Date(now), sb, fp); if (sb.charAt(fp.getBeginIndex()) == '0') { sb.setCharAt(fp.getBeginIndex(), ' '); } date = sb.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); date = sdf.format(new Date(now)); } cache.put(pattern, date); } return date; }
FastDateFormat { public String getDate(long now, String pattern) { sameDay(now); String date = cache.get(pattern); if (date == null) { if (MMM_D2.equals(pattern)) { StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.Field.DAY_OF_MONTH); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd", locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); sdf.format(new Date(now), sb, fp); if (sb.charAt(fp.getBeginIndex()) == '0') { sb.setCharAt(fp.getBeginIndex(), ' '); } date = sb.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); date = sdf.format(new Date(now)); } cache.put(pattern, date); } return date; } }
FastDateFormat { public String getDate(long now, String pattern) { sameDay(now); String date = cache.get(pattern); if (date == null) { if (MMM_D2.equals(pattern)) { StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.Field.DAY_OF_MONTH); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd", locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); sdf.format(new Date(now), sb, fp); if (sb.charAt(fp.getBeginIndex()) == '0') { sb.setCharAt(fp.getBeginIndex(), ' '); } date = sb.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); date = sdf.format(new Date(now)); } cache.put(pattern, date); } return date; } FastDateFormat();  FastDateFormat(TimeZone timeZone, Locale locale); }
FastDateFormat { public String getDate(long now, String pattern) { sameDay(now); String date = cache.get(pattern); if (date == null) { if (MMM_D2.equals(pattern)) { StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.Field.DAY_OF_MONTH); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd", locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); sdf.format(new Date(now), sb, fp); if (sb.charAt(fp.getBeginIndex()) == '0') { sb.setCharAt(fp.getBeginIndex(), ' '); } date = sb.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); date = sdf.format(new Date(now)); } cache.put(pattern, date); } return date; } FastDateFormat();  FastDateFormat(TimeZone timeZone, Locale locale); boolean sameDay(long now); String getDate(long now, String pattern); void writeTime(long now, boolean writeMillis, Appendable buffer); }
FastDateFormat { public String getDate(long now, String pattern) { sameDay(now); String date = cache.get(pattern); if (date == null) { if (MMM_D2.equals(pattern)) { StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(DateFormat.Field.DAY_OF_MONTH); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd", locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); sdf.format(new Date(now), sb, fp); if (sb.charAt(fp.getBeginIndex()) == '0') { sb.setCharAt(fp.getBeginIndex(), ' '); } date = sb.toString(); } else { SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); sdf.setCalendar(Calendar.getInstance(timeZone, locale)); date = sdf.format(new Date(now)); } cache.put(pattern, date); } return date; } FastDateFormat();  FastDateFormat(TimeZone timeZone, Locale locale); boolean sameDay(long now); String getDate(long now, String pattern); void writeTime(long now, boolean writeMillis, Appendable buffer); static final String YYYY_MM_DD; static final String MMM_D2; static final String XXX; }