The php processing date format is seconds ago, minutes ago, hours ago, yesterday, and the day before yesterday.
Source: http://www.crazyphper.com
- /**
- * Change the date format to different display styles according to the following rules:
- * The number of seconds before the display time is less than 1 minute
- * The number of minutes before the display time is less than 1 hour
- * How many hours ago are displayed in a day?
- * Within three days, or the day before yesterday is displayed.
- * 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 (); // get today's 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. "minutes ago ";
- Break;
- // Day
- Case ($ sorce_date + 3600*24)> = self: $ nowTime:
- $ Temp_time = date ('H', self: $ nowTime)-date ('H', $ sorce_date );
- $ TimeHtml = $ temp_time. 'hour before ';
- 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 Day'. $ temp_time;
- Break;
- // 3 days ago
- Case ($ sorce_date + 3600*24*4)> = self: $ nowTime:
- $ TimeHtml = '3 days ago ';
- Break;
- Default:
- $ TimeHtml = date ('Y-m-D', $ sorce_date );
- Break;
- }
- Return $ timeHtml;
- }
|