Here you can find the source of getTimeOf12(long time)
private static String getTimeOf12(long time)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private static String getTimeOf12(long time) { return getAmPm(time) + " " + getTimeStr(getHourOf12(time), getMinute(time), true); }// w w w . ja v a2s .c om private static String getAmPm(long time) { SimpleDateFormat sf = new SimpleDateFormat("aa"); return sf.format(new Date(time)); // return getAmPmStr(time) == 0 ? mContext.getString(AM) : mContext.getString(PM); } private static String getTimeStr(int hour, int minute, boolean is12) { StringBuilder temp = new StringBuilder(); if (is12) { temp.append(hour); } else { temp.append(toTwoDigits(hour)); } temp.append(":"); temp.append(toTwoDigits(minute)); return temp.toString(); } private static int getHourOf12(long time) { int hour = currentDateTime(time, Calendar.HOUR); if (hour == 0) hour = 12; return hour; } private static int getMinute(long time) { return currentDateTime(time, Calendar.MINUTE); } private static String toTwoDigits(int digit) { if (digit >= 10) { return "" + digit; } else { return "0" + digit; } } private static int currentDateTime(long time, int type) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar.get(type); } }