Php calculation time difference php date conversion example
|
The code for calculating the time difference counts the number of days. I remember that I had seen it in other programs converted to year, month, and day. so I wrote it by hand. In fact, it was quite simple, just a few conversions, however, the monthly statistics are not very accurate, because I don't know how many days it will take to convert it into a month of 30 days, and the error should be small. this cannot be solved.
Example: code for calculating the site creation time: $ jztime site creation time format: 2013-01-01
- $ Days = abs (strtotime ($ jztime)-strtotime (date ("Y-m-d")/86400;
- If ($ days & gt; 365 ){
- $ Site_Y = intval ($ days/365). "Year -";
- }
- If ($ days> 31 ){
- $ Str = explode (".", $ days/365); // obtain the data of more than one year
- $ Site_m = ("0.". $ str [(count ($ str)-1)]) * 365/30;
- $ Site_m = intval ($ site_m). "month -";
- } Bbs.it-home.org
- If ($ days> 1 ){
- $ Str = explode (".", $ days/365); // continue to obtain the remaining data
- $ Site_d = ("0.". $ str [(count ($ str)-1)]) * 365-(intval ($ site_m) * 30 );
- $ Site_d = intval ($ site_d). "day ";
- }
- $ Dayst = $ site_Y. $ site_m. $ site_d;
- Echo $ dayst;
- ?>
|