This article mainly introduces the date and time processing tool (Carbon) in PHP, which has a certain reference value, if you are interested, please take a look at this article. This article mainly introduces the date and time processing tool instance (Carbon) in PHP, which has some reference value. if you are interested, please take a look at it.
Carbon introduction
Carbon is a user-friendly time and date processing plug-in PHP. github has nearly 5000 stars.
Github: https://github.com/briannesbitt/Carbon
Carbon Basic usage
// 1. basic application $ now = Carbon: now (); // 14:13:16 $ today = Carbon: today (); // 00:00:00 $ tomorrow = Carbon :: tomorrow (); // 00:00:00 $ yesterday = Carbon: yesterday (); // 00:00:00 // 2. determine if it is a certain day (Thursday) $ now = Carbon: now (); var_dump ($ now-> isWeekend (); // false because Thursday is not a weekend var_dump ($ now-> isWeekday ()); // true because Thursday is the workday var_dump ($ now-> isThursday (); // true because today is the Thursday $ now-> isToday (); $ now-> isTomorrow (); $ now-> isFuture (); $ now-> isPast (); // 3. create a carbon object for a certain day and perform addition and subtraction calculation $ date = Carbon: create (2016, 12, 25, 0, 0, 0 ); // 00:00:00 $ next_year = $ date-> addYears (2); // 00:00:00 $ past_year = $ date-> subYears (2 ); // 00:00:00 $ next_month = $ date-> addMonths (2); // 00:00:00 $ past_month = $ date-> subMonths (2 ); // 00:00:00 $ next_day = $ date-> addDays (2); // 00:00:00 $ past_day = $ date-> subDays (2); // 00:00:00... addWeekdays (), addWeeks (), addHours (), and other methods // 4. convert the carbon object to the string type $ dt = Carbon: create (1975, 12, 25, 14, 15, 16); echo $ dt-> toDateString (); // 1975-12-25echo $ dt-> toFormattedDateString (); // Dec 25,197 5 echo $ dt-> toTimeString (); // 14: 15: 16 echo $ dt-> toDateTimeString (); // 1975-12-25 14: 15: 16 echo $ dt-> toDayDateTimeString (); // Thu, Dec 25,197
The above describes some basic Carbon usage. Carbon is flexible and user-friendly.
The above is a detailed description of the Carbon instance in PHP. For more information, see other related articles in the first PHP community!