zoukankan      html  css  js  c++  java
  • 一个时间转换的功能的类

    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米左右" ;
    		}
    	}
    	
    	
    }
    

      

  • 相关阅读:
    Python 高级编程系列__03:python 中常见的内置类型
    Python 高级编程系列__02:type、object、class 的关系
    Python 高级编程系列__01:一切皆对象
    Mac 修改默认python的版本
    swap指令实现互斥
    什么是进程同步?wait( )是如何实现进程同步的?
    可执行文件加载时进行了哪些处理?
    C++不允许使用不完整的类型说明
    error LNK2019: 无法解析的外部符号
    抽屉原理——放苹果
  • 原文地址:https://www.cnblogs.com/chuiyuan/p/4446043.html
Copyright © 2011-2022 走看看