Android time Conversion

Source: Internet
Author: User
// Convert GMT time to long time public static long getlongbygmt (string gmttime) throws parseexception {simpledateformat GMT = new simpledateformat ("Eee, d Mmm yyyy hh: mm: ss z ", locale. english); Return GMT. parse (gmttime ). gettime () ;}// format the display time public static string displaytime (long timestamp) {simpledateformat MH = new simpledateformat ("mm-dd hh: mm: SS "); simpledateformat Hm = new simpledateformat ("HH: mm: SS"); long currentseconds = system. currenttimemillis (); // The current system time string timestr = NULL; long currentstart = currentseconds-currentseconds % (24*60*60*1000); long timegap = (currentstart-timestamp) /1000; // seconds different from the current early morning time if (timegap <= 0) // Today {timestr = HM. format (timestamp);} else if (timegap> 0 & timegap <= 24*60*60) {timestr = "yesterday" + HM. format (timestamp); // Yesterday} else if (timegap> 24*60*60 & timegap <= 2*24*60*60) {timestr = "the day before yesterday" + HM. format (timestamp); // the day before yesterday} else {timestr = MH. format (timestamp);} return timestr;} // obtain the time value public static string getnormaltime (long value) based on long data) {simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); string time = format. format (new date (value); return time ;}
Related Article

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.