This article mainly introduces the date time processing tool in PHP example (Carbon), with a certain reference value, interested can understand
Carbon Introduction
Carbon is a very user-friendly time-date processing plugin in PHP, with a proximity of 5,000 star on GitHub.
The GitHub address is: Https://github.com/briannesbitt/Carbon
Carbon Basic usage
1, basic Application $now = Carbon::now (); 2016-11-03 14:13:16$today = Carbon::today (); 2016-11-03 00:00:00$tomorrow = Carbon::tomorrow (); 2016-11-04 00:00:00$yesterday = Carbon::yesterday (); 2016-11-02 00:00:00//2, judge whether one day (2016-11-03 (Thursday) example) $now = Carbon::now (); Var_dump ($now->isweekend ());//false Since Thursday is not a weekend Var_dump ($now->isweekday ()),//true because Thursday is a weekday var_dump ($now->isthursday ());//true because today is Thursday $now-> IsToday (); $now->istomorrow (); $now->isfuture (); $now->ispast ();//3, creates a Carbon object for a day, and calculates the addition and subtraction of the date = Carbon:: Create (0, 0, 0),//2016-12-25 00:00:00$next_year= $date->addyears (2);//2018-12-25 00:00:00$past_year=$ Date->subyears (2);//2014-12-25 00:00:00$next_month= $date->addmonths (2);//2017-02-25 00:00:00$past_month=$ Date->submonths (2);//2016-10-25 00:00:00$next_day= $date->adddays (2);//2016-12-27 00:00:00$past_day= $date- >subdays (2);//2016-12-23 00:00:00 ... more addweekdays (), Addweeks (), addHours ()//4, convert Carbon object to String type $DT = Carbon::creaTe (1975, N, +, +), echo $dt->todatestring (); 1975-12-25echo $dt->toformatteddatestring (); Dec, 1975echo $dt->totimestring (); 14:15:16echo $dt->todatetimestring (); 1975-12-25 14:15:16echo $dt->todaydatetimestring (); Thu, Dec, 1975 2:15 PM
The
Above describes some of the basic carbon used. The biggest feature of carbon is the flexibility and humanization.