Format Date Timestamp in HH:mm:ss a format - Android java.util

Android examples for java.util:Date Format

Description

Format Date Timestamp in HH:mm:ss a format

Demo Code

import android.app.Activity;
import android.text.format.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main{

    public static String formatDateTimestamp(long timestamp) {
        Calendar cal = Calendar.getInstance();
        TimeZone tz = cal.getTimeZone();

        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss a");
        sdf.setTimeZone(tz);// w w w.  j a  v  a 2 s  . c om

        String localTime = sdf.format(new Date(timestamp));
        return localTime;
    }

}

Related Tutorials