Share a tool for date and time processing in PHP

Source: Internet
Author: User
Tags php example
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.

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.