获取Android系统时间

目的: 输入 2014-09-09 14:02:03

      输出 等待:1小时20分

注意: HH:mm:ss 为获取手机 24小时格式的时间    15:03

      hh:mm:ss 为12小时模式的时间        03:03

@SuppressLint("SimpleDateFormat")
public static String getTimeLeft(String date1) {
if (date1 == null || date1.equals(""))
return null;
String str = date1.substring(11,19);
int[] times1=new int[3];
int[] times2=new int[3];

times1[0] = Integer.parseInt(str.substring(0,2));
times1[1] = Integer.parseInt(str.substring(3,5));
times1[2] = Integer.parseInt(str.substring(6));

String today = getNowTime("HH:mm:ss");
times2[0] = Integer.parseInt(today.substring(0,2));
times2[1] = Integer.parseInt(today.substring(3,5));
times2[2] = Integer.parseInt(today.substring(6));

String result = "";
long timeall = times2[0]*60*60 +times2[1]*60+times2[2]-(times1[0]*60*60+times1[1]*60+times1[2]);

long h = timeall/(60*60);
long m = timeall/60%60;
long s = timeall%60;

if(h>0){
result +=h+"小时";
}

if(m>0){
result +=m+"分钟";
}

if(s>0){
result +=s+"秒";
}

return result;
}

上一篇:HDU 1083 Courses 【二分图完备匹配】


下一篇:HDU - 1083 Courses /POJ - 1469