• 一个时间转换的功能的类


    package com.xgr.wonderful.utils;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    import android.R.integer;
    import android.app.PendingIntent.CanceledException;
    import android.widget.HorizontalScrollView;
    
    import com.easemob.util.DateUtils;
    import com.xgr.wonderful.constant.Constant;
    
    public class DisplayUtils {
    	public static final int ONE_MIN = 60;
    	public static final int ONE_HOUR = 3600;
    	
    	private static final String TAG = "DisplayUtils";
    	
    	public static String transformTime(long timestamp){
    		Calendar calendar = Calendar.getInstance();
    		//状态发表的时间
    		calendar.setTime(new Date(timestamp));
    		int year1 = calendar.get(Calendar.YEAR);
    		int month1 = calendar.get(Calendar.MONTH)+1 ;//从0开始,应该加1
    		int dayOfMonth1= calendar.get(Calendar.DAY_OF_MONTH);
    		int hour1 = calendar.get(Calendar.HOUR_OF_DAY) ;
    		int minute1 = calendar.get(Calendar.MINUTE);
    		LogUtils.i(TAG, "status:"+year1+" "+month1+" "+dayOfMonth1+" "+minute1);
    		//现在的时间
    		calendar.setTime(new Date());
    		int year = calendar.get(Calendar.YEAR);
    		int month = calendar.get(Calendar.MONTH)+1 ;//从0开始,应该加1
    		int dayOfMonth= calendar.get(Calendar.DAY_OF_MONTH);
    		int hour = calendar.get(Calendar.HOUR_OF_DAY) ;
    		int minute = calendar.get(Calendar.MINUTE);
    		LogUtils.i(TAG, "now"+year+" "+month+" "+dayOfMonth+" "+minute);
    		
    		String time = null;
    		// 一般情况 下是满足这个 的
    		if (year1 == year && month1 == month) {
    			if (dayOfMonth1 == dayOfMonth) {
    				// 今天
    				if (hour1 == hour){
    					time = (minute-minute1)+"分钟前";
    				}else {
    					time =  hour1 + ":" + minute1;
    				}
    			} else if (dayOfMonth - dayOfMonth1 == 1) {
    				// 昨天
    				time = "昨天" + hour1 + ":" + minute1;
    			} else {
    				// 两天前,直接显示时间
    				time = month1 + "月" + dayOfMonth1 + "日 " + hour1 + ":"
    						+ minute1;
    			}
    		} else {
    			time = year1 + "年" + month1 + "月" + dayOfMonth1 + "日";
    		}
    		
    		return time ;
    	}
    	
    	public static String transformDistance(Long distance) {
    		float distance1 = distance;
    		float res = distance1/1000;
    		if (res>=1){
    			return "约"+(int)res+"千米";
    		}else if (distance/100 >=1){ 
    			return (int)(distance/100)+"00米" ;
    		}else {
    			return "100米左右" ;
    		}
    	}
    	
    	
    }
    

      

  • 相关阅读:
    Jython:java调用python文件之第三方包路径问题
    待研究的技术第二版
    mysql主从数据库不同步的2种解决方法(转)
    mysql分表和表分区详解
    mysql-binlog日志恢复数据库
    mysql delete删除记录数据库空间不减少问题解决方法
    mySQL 增量备份方案(转)
    mysql 查看 删除 日志操作总结(包括单独和主从mysql)
    Memcache的部署和使用(转)
    Linux下memcache的安装和启动(转)
  • 原文地址:https://www.cnblogs.com/chuiyuan/p/4446043.html
Copyright © 2020-2023  润新知