android 时间转换

原文 http://blog.csdn.net/zhuqiang1002/article/details/7527361

[java]  view plain copy print ?
  1. //把GMT时间转化为Long时间  
  2. public static long getLongByGMT(String gmtTime) throws ParseException  
  3. {  
  4.     SimpleDateFormat Gmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z",Locale.ENGLISH);     
  5.     return Gmt.parse(gmtTime).getTime();  
  6. }  
  7.   
  8. //格式化显示时间  
  9. public static String displayTime(long timestamp)  
  10. {  
  11.       
  12.     SimpleDateFormat mh = new SimpleDateFormat("MM-dd HH:mm:ss");  
  13.     SimpleDateFormat hm = new SimpleDateFormat("HH:mm:ss");  
  14.     long currentSeconds = System.currentTimeMillis();//系统当前时间  
  15.      String timeStr = null;  
  16.     long currentStart = currentSeconds - currentSeconds % (24 * 60 * 60 * 1000);  
  17.     long timeGap = (currentStart - timestamp) / 1000;// 与当前凌晨时间相差秒数  
  18.      if (timeGap <= 0)//今天  
  19.      {  
  20.     timeStr = hm.format(timestamp);  
  21.     }  
  22.     else if (timeGap > 0 && timeGap <= 24 * 60 * 60)  
  23.     {  
  24.     timeStr = "昨天" + hm.format(timestamp);// 昨天  
  25.      }  
  26.     else if (timeGap > 24 * 60 * 60 && timeGap <= 2 * 24 * 60 * 60)  
  27.     {  
  28.     timeStr = "前天" + hm.format(timestamp);// 前天  
  29.      }  
  30.     else  
  31.     {  
  32.     timeStr = mh.format(timestamp);  
  33.     }  
  34.     return timeStr;  
  35. }  
  36. //根据long型的数据获取时间值  
  37. public static String getNormalTime(long value)  
  38. {  
  39.     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;  
  40.     String time = format.format(new Date(value)) ;  
  41.     return time;  
  42. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值