首页 > 其他 > 详细

时间工具

时间:2014-08-08 17:40:06      阅读:306      评论:0      收藏:0      [点我收藏+]
public static String getTimeForShowing(String strTime)  
    {  
        System.out.println(strTime);
        //
        int year = Integer.parseInt(strTime.substring(0, 4));  
        //
        int month = Integer.parseInt(strTime.substring(5, 7));  
        //日期  
        int day = Integer.parseInt(strTime.substring(8, 10));  
        //小时  
        int hour = Integer.parseInt(strTime.substring(11, 13));  
        //分钟  
        int minute = Integer.parseInt(strTime.substring(14, 16));  
        //
        int second = Integer.parseInt(strTime.substring(17, 19));  
        Calendar now  = Calendar.getInstance();  
        Calendar dynamicT = Calendar.getInstance();  
        dynamicT.set(year, month - 1, day, hour, minute, second);  
        long intermill = (now.getTimeInMillis() - dynamicT.getTimeInMillis()) / 1000;  
        if (intermill < 60) {  
            //60秒以内  
            return "刚才";  
        } else if (intermill < 3600) {  
            //60分钟以内  
            return (intermill / 60) + "分钟前";  
        } else if (intermill < 3600 * 24) {  
            //24小时以内  
            return (intermill/(3600)) + "小时前";  
        } else if (intermill < 3600 * 24 * 30) {  
            //一个月以内  
            return (intermill / (3600 * 24)) + "天前";  
        } else if (intermill < 3600 * 24 * 365) {  
            //一年以内  
            return month + "月" + day + "日";  
        } else {  
            //一年以上  
            StringBuffer buff = new StringBuffer(Integer.toString(year)).append("年");  
            buff.append(month).append("月");  
            buff.append(day).append("日");  
            return  buff.toString() ;  
        }  
    } 
public static String getNow() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }

 

时间工具,布布扣,bubuko.com

时间工具

原文:http://www.cnblogs.com/fudapeng/p/3899562.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!