×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel ¸Ä±äʱ¼äÃûÌÃ

laravelÊÇÒ»ÖÖ»ùÓÚphpµÄwebÓ¦ÓóÌÐò¿ª·¢¿ò¼Ü£¬ËüÌṩÁ˶àÖÖ¹¦Ð§ºÍ¹¤¾ß£¬¿ÉÒÔÉÁ¿ª·¢Ö°Ô±¸ü¿ì¡¢¸üÇáËɵؿª·¢Ó¦ÓóÌÐò¡£ÆäÖÐÒ»¸ö³£¼ûµÄÎÊÌâ¾ÍÊÇÔõÑùÔÚlaravelÖиü¸Äʱ¼äÃûÌá£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÉîÈë̽ÌÖÔõÑùʹÓÃlaravelÀ´¸ü¸Äʱ¼äÃûÌá£

LaravelÖеÄʱ¼äÃûÌû¯

ÔÚLaravelÖÐʹÓÃʱ¼äÃûÌû¯£¬¿ÉÒÔʹÓÃPHPµÄʱ¼äº¯Êý»òCarbon¿â£¬CarbonÊÇÒ»¸öÊ¢ÐеÄPHPʱ¼ä´¦Àí¿â£¬ÌṩÁ˸ü¶àÀû±ãµÄÒªÁì¡£

Carbon¿âµÄ×°ÖÃ

ҪʹÓÃCarbon¿â£¬¿ÉÒÔͨ¹ýComposer×°Öãº

composer require nesbot/carbon

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó£¬¿ÉÒÔͨ¹ýÒÔÏÂÒªÁìÔÚLaravelÖÐʹÓÃCarbon£º

use CarbonCarbon;

µÇ¼ºó¸´ÖÆ

Carbon¿âµÄʹÓÃ

ÏÂÃæÊÇCarbon¿â¿ÉÓõÄһЩҪÁ죺

»ñÈ¡Ä¿½ñÈÕÆÚʱ¼ä£º

Carbon::now();

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ö¸¶¨ÈÕÆÚʱ¼ä£º

Carbon::parse('2021-05-01 15:00:00');

µÇ¼ºó¸´ÖÆ

»ñȡʱ¼ä´Á£º

Carbon::now()->timestamp;

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ö¸¶¨ÌìÊýºóµÄÈÕÆÚ£º

Carbon::now()->addDays(5);

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ä¿½ñʱ¼äµÄÄê·Ý£º

Carbon::now()->year;

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ä¿½ñʱ¼äµÄÔ·ݣº

Carbon::now()->month;

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ä¿½ñʱ¼äÊÇÐÇÆÚ¼¸£º

Carbon::now()->dayOfWeek;

µÇ¼ºó¸´ÖÆ

»ñÈ¡Ä¿½ñʱ¼äÊÇÒ»ÄêÖеĵڼ¸Ì죺

Carbon::now()->dayOfYear;

µÇ¼ºó¸´ÖÆ

ÔÚLaravelÖиü¸Äʱ¼äÃûÌÃ

ÔÚLaravelÖиü¸Äʱ¼äÃûÌõÄÒªÁìÓÐÐí¶à£¬ÏÂÃæǨ¾Í³£Óõļ¸ÖÖÒªÁì¾ÙÐнâ˵¡£

ʹÓÃCarbon¿âÖеÄformatÒªÁì

ʹÓÃCarbon¿âÖеÄformatÒªÁì¿ÉÒÔÀû±ãµØ¸ü¸Äʱ¼äÃûÌá£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

$now = Carbon::now();
$formatTime = $now->format('Y-m-d H:i:s');

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂ뽫·µ»ØÃûÌÃΪ¡°2021-05-20 14:30:00¡±µÄÄ¿½ñʱ¼ä¡£

Carbon::parse(‘2021-05-01 15:00:00’)->format(‘YÄêmÔÂdÈÕ H:i:s’);

ʹÓÃformatÒªÁìʱ£¬ÐèҪעÖØʹÓõĴúÂë·ûºÅ£¬¿ÉÒԲο¼Carbon¿âµÄ¹Ù·½Îĵµ¾ÙÐÐÑ¡Ôñ¡£

ʹÓÃPHPÖеÄdateÒªÁì

PHPÖеÄdateÒªÁìÒ²¿ÉÒÔÀû±ãµØ¸ü¸Äʱ¼äÃûÌá£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

$now = time();
$formatTime = date('Y-m-d H:i:s', $now);

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂ뽫·µ»ØÃûÌÃΪ¡°2021-05-20 14:30:00¡±µÄÄ¿½ñʱ¼ä¡£

dateº¯ÊýÖеĵÚÒ»¸ö²ÎÊýΪʱ¼äÃûÌ㬵ڶþ¸ö²ÎÊýΪUnixʱ¼ä´Á¡£

ʹÓÃLaravelÖеÄʱ¼äº¯Êý

LaravelÖÐÌṩÁËһЩ×Ô½ç˵µÄʱ¼äº¯Êý£¬ÈçtoDateString()¡¢toTimeString()¡¢toDateTimeString()µÈ¡£ÕâЩº¯Êý¿ÉÒÔÀû±ãµØ¸ü¸Äʱ¼äÃûÌá£

ÀýÈ磺

$now = now();
$formatDate = $now->toDateString();
$formatTime = $now->toTimeString();
$formatDateTime = $now->toDateTimeString();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂ뽫»®·Ö·µ»ØÃûÌÃΪ¡°2021-05-20¡±µÄÄ¿½ñÈÕÆÚ£¬ÃûÌÃΪ¡°14:30:00¡±µÄÄ¿½ñʱ¼ä£¬ÒÔ¼°ÃûÌÃΪ¡°2021-05-20 14:30:00¡±µÄÄ¿½ñÈÕÆÚºÍʱ¼ä¡£

×ܽá

ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËʹÓÃLaravelÀ´¸ü¸Äʱ¼äÃûÌõļ¸ÖÖÒªÁ죬°üÀ¨Ê¹ÓÃCarbon¿âµÄformatÒªÁì¡¢PHPÖеÄdateÒªÁìÒÔ¼°LaravelÖеÄ×Ô½ç˵ʱ¼äº¯Êý¡£ÔÚÏÖʵӦÓÃÖУ¬¿ª·¢Ö°Ô±¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóÑ¡ÔñºÏÊʵÄÒªÁì¾ÙÐвÙ×÷¡£

ÒÔÉϾÍÊÇlaravel ¸Ä±äʱ¼äÃûÌõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Á¢³¡£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ