Php disposal date format: seconds ago, minutes ago, hours ago, yesterday, the day before yesterday

Source: Internet
Author: User
The date format of php processing is seconds ago, minutes ago, hours ago, yesterday, and the day before yesterday. *** modify the date format to different display styles according to the following rules * The number of seconds before Display is less than 1 minute * Less than 1 hour, how many minutes ago * one day, how many hours ago * 3 days ago, display the day before yesterday or yesterday: 12: 23. * If it exceeds 3 days, the complete date is displayed. * The php processing date format is seconds ago, minutes ago, hours ago, yesterday, and the day before yesterday.
/*** Modify the date format to different display styles according to the following rules * The number of seconds before the display is less than 1 minute * Less than 1 hour, and the number of minutes before the Display * within one day, how many hours ago * 3 days ago, display the day before yesterday or yesterday: 12: 23. * If it exceeds 3 days, the complete date is displayed. * @ Static * @ param $ sorce_date date unix timestamp * @ return void */public static function getDateStyle ($ sorce_date) {self: $ nowTime = time (); // Obtain the current timestamp // echo 'data source timestamp :'. $ sorce_date. '= '. date ('Y-m-d H: I: S', $ sorce_date); // echo "\ n current timestamp :". date ('Y-m-d H: I: S', self: $ nowTime ). "\ n"; $ timeHtml = ''; // return text format $ temp_time = 0; switch ($ sorce_date) {// One-Minute case ($ sorce_date + 60)> = self: $ nowTime: $ temp_time = self ::$ nowTime-$ sorce_date; $ timeHtml = $ temp_time. "Seconds ago"; break; // hour case ($ sorce_date + 3600)> = self: $ nowTime: $ temp_time = date ('I', self :: $ nowTime-$ sorce_date); $ timeHtml = $ temp_time. "Minute Ago"; break; // day case ($ sorce_date + 3600*24)> = self: $ nowTime: $ temp_time = date ('H', self :: $ nowTime)-date ('H', $ sorce_date); $ timeHtml = $ temp_time. 'hour ago '; break; // yesterday case ($ sorce_date + 3600*24*2)> = self: $ nowTime: $ temp_time = date ('H: I ', $ sorce_date); $ timeHtml = 'Yesterday '. $ temp_time; break; // The day before yesterday case ($ sorce_date + 3600*24*3)> = self: $ nowTime: $ temp_time = date ('H: I ', $ sorce_date); $ timeHtml = 'day before yesterday '. $ temp_time; break; // case 3 days ago ($ sorce_date + 3600*24*4)> = self: $ nowTime: $ timeHtml = '3 days'; break; default: $ timeHtml = date ('Y-m-D', $ sorce_date); break;} return $ timeHtml ;}

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.