Android examples for java.util:Calendar
Format Date by appending Calendar field together
import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ClickableSpan; import android.view.View; import java.util.Calendar; import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String getDateFormat(long milliseconds, String format) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(milliseconds); StringBuilder sb = new StringBuilder(); if (format.equals("yy-mm-dd")) { sb.append(c.get(Calendar.YEAR)).append("-") .append(c.get(Calendar.MONTH) + 1).append("-") .append(c.get(Calendar.DAY_OF_MONTH)); } else if (format.equals("mm-dd")) { sb.append(c.get(Calendar.MONTH)).append("-") .append(c.get(Calendar.DAY_OF_MONTH)); }/* ww w . j a v a 2 s .c om*/ return sb.toString(); } }