get Morning Or Afternoon - Android java.util

Android examples for java.util:Date Time

Description

get Morning Or Afternoon

Demo Code

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 {/*www . j ava 2  s.  co m*/
            am = "AM";
        }

        tv_time.setText(am);

        return am;
    }

}

Related Tutorials