Android examples for java.util:Date Time
get Morning Or Afternoon
import android.annotation.SuppressLint; import android.widget.TextView; import java.text.ParseException; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ public static String getMorningOrAfternoon(long time, TextView tv_time) { Calendar mCalendar = Calendar.getInstance(); mCalendar.setTimeInMillis(time); int apm = mCalendar.get(Calendar.HOUR_OF_DAY); String am = ""; if (apm > 18 || apm < 6) { am = "PM"; } else {// ww w . j a v a2 s . co m am = "AM"; } tv_time.setText(am); return am; } }