Here you can find the source of getMonthDayString(long l, boolean timezone, boolean formated)
public static String getMonthDayString(long l, boolean timezone, boolean formated)
//package com.java2s; //License from project: LGPL public class Main { private static long accmulated_timemillis_year[]; private static long accmulated_timemillis_month[]; private static long accmulated_timemillis_month_leapyear[]; private static long accmulated_timemillis_2002 = 0L; private static int timeZoneOffset = 0; static final char DigitTens[] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9' }; static final char DigitOnes[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; public static String getMonthDayString(long l, boolean timezone, boolean formated) { if (timezone) l += timeZoneOffset;/* ww w . j a va 2 s .c om*/ if (l < 0L) return formated ? "01-01" : "0101"; if (l > accmulated_timemillis_year[229]) return formated ? "12-31" : "1231"; int year = 9999; int mon = 0; boolean leap_year = false; if (l > accmulated_timemillis_2002) { for (int y = 2003; y < 2199; y++) { if (l >= accmulated_timemillis_year[y - 1970]) continue; year = y; break; } } else { for (int y = 1970; y < 2200; y++) { if (l >= accmulated_timemillis_year[y - 1970]) continue; year = y; break; } } if (year > 1970) l -= accmulated_timemillis_year[year - 1970 - 1]; if (isLeapYear(year)) { for (int m = 0; m < 12; m++) { if (l >= accmulated_timemillis_month_leapyear[m]) continue; mon = m; if (m > 0) l -= accmulated_timemillis_month_leapyear[m - 1]; break; } } else { for (int m = 0; m < 12; m++) { if (l >= accmulated_timemillis_month[m]) continue; mon = m; if (m > 0) l -= accmulated_timemillis_month[m - 1]; break; } } int day = (int) (l * 0x31b5d43bL >>> 56); l -= (long) day * 0x5265c00L; char buf[] = formated ? new char[5] : new char[4]; if (formated) { buf[0] = DigitTens[++mon]; buf[1] = DigitOnes[mon]; buf[2] = '-'; buf[3] = DigitTens[++day]; buf[4] = DigitOnes[day]; } else { buf[0] = DigitTens[++mon]; buf[1] = DigitOnes[mon]; buf[2] = DigitTens[++day]; buf[3] = DigitOnes[day]; } return new String(buf); } private static boolean isLeapYear(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } }