日期转为昨天,今天,明天。。

/**
     * 将时间 换为人性化的时间
     * 01-05 17:43
     * @param date
     * @return
     */
    public static String makeLovelyDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(PATTEN_YEAR_MM_DD);
        String timePattern = " HH:mm";
        String weekPattern = "E";
        String dateString;

        long timeMinus = 0L;
        timeMinus = (date.getTime()) - System.currentTimeMillis() ;
        int n = new Double(Math.floor(timeMinus / 24D/3600/1000)).intValue();
        if(n == -1)
        {
            dateString = "昨天" ;
        }else if(n == 0)
        {
            dateString = "今天";
        }else if(n == 1)
        {
            dateString = "明天";
        }else if(n >= 2 && n <= 5)
        {
            dateString = FastDateFormat.getInstance(weekPattern, Locale.CHINESE).format(date);
        }else
        {
            dateString = sdf.format(date);
        }
        dateString = dateString  + FastDateFormat.getInstance(timePattern).format(date);
        return dateString;

    }

 

/**
	 * 日期转为昨天,今天,明天
	 */
	public static String convertDate(Date date){
		Calendar today = Calendar.getInstance();
		Calendar old = Calendar.getInstance();
		old.setTime(date);

		today.set(Calendar.HOUR, 0);
		today.set(Calendar.MINUTE, 0);
		today.set(Calendar.SECOND, 0);
		old.set(Calendar.HOUR, 0);
		old.set(Calendar.MINUTE, 0);
		old.set(Calendar.SECOND, 0);

		//老的时间减去今天的时间
		long intervalMilli = old.getTimeInMillis() - today.getTimeInMillis();
		int xcts = (int) (intervalMilli / (24 * 60 * 60 * 1000));
		// -2:前天 -1:昨天 0:今天 1:明天 2:后天, out:显示日期
		if (xcts == -2) {
			return "前天";
		} else if (xcts == -1) {
			return "昨天";
		} else if (xcts == 0) {
			return "今天";
		} else if (xcts == 1) {
			return "明天";
		}else if (xcts == 2) {
			return "后天";
		}else{
			return "====";
		}

	}

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值