"Java" Prettytime

Source: Internet
Author: User

Package Test;import java.text.parseexception;import Java.text.simpledateformat;import java.util.Date;/** * Created by Luan on 2015/9/15.  */public class prettytime{Private final static long minute = 60 * 1000;//1 min Private final static long hour = 60 * minute;//1 hours private final static long day = hour;//1 days private final static long month = * day;//Month PR Ivate final static long year = month;//years public static void main (string[] args) throws ParseException {St        Ring m = "2015-09-15 09:35:01";    System.out.printf (Gettimeformattext (m));        /** * Returns the date of the literal description * @param date * @return */public static string Gettimeformattext (string date) {        SimpleDateFormat f = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");        Date D;        try {d = f.parse (date);        } catch (ParseException e) {return date;    } return Gettimeformattext (d); }/** * Returns the date of the text description * * @param date * @return */public static String Gettimeformattext (date date) {if (date = = null) {return null;        } long diff = new Date (). GetTime ()-date.gettime ();        Long r = 0;            if (diff > year) {r = (diff/year);        Return r + "years ago";            } if (diff > month) {r = (diff/month);        return r + "months ago";            } if (diff > day) {r = (diff/day);        return r + "days Ago";            } if (diff > hour) {r = (diff/hour);        Return r + "hours ago";            } if (diff > minute) {r = (Diff/minute);        return r + "minutes ago";    } return "just"; }}

  

"Java" Prettytime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.