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

      

  • 相关阅读:
    MATLAB矩阵操作【z】
    matlab绘图方法[z]
    Drawhere 有趣的网页涂鸦工具【z】
    DemoHelper,针对电脑演示的小工具
    Matlab Matrix [z]
    MATLAB函数参考[z]
    计算几何常用算法概览[z]
    matlab命令行环境的常用操作[z]
    不常见数学符号或简写
    matlab加入上级路径和本级路径的方法
  • 原文地址:https://www.cnblogs.com/chuiyuan/p/4446043.html
Copyright © 2011-2022 走看看