Home  >  Article  >  Backend Development  >  How does Carbon determine what day of the week it is?

How does Carbon determine what day of the week it is?

WBOY
WBOYOriginal
2016-07-06 13:51:502982browse

Using Carbon in Laravel, how to determine what day of the week today is?

Also,

<code>如何将Carbon::now()得到的结果裁剪成类似这样的格式:20160628;
如何将20160628这样的格式转成Carbon::now()->dayOfYear.
</code>

If there is a Chinese document or tutorial on carbon, please give an address. There is too little time and it is too slow to read the official document.

Thank you!

Reply content:

Using Carbon in Laravel, how to determine what day of the week today is?

Also,

<code>如何将Carbon::now()得到的结果裁剪成类似这样的格式:20160628;
如何将20160628这样的格式转成Carbon::now()->dayOfYear.
</code>

If there is a Chinese document or tutorial on carbon, please give an address. There is too little time and it is too slow to read the official document.

Thank you!

Using PHP native method.

carbon is an external dependency package, you can take a look at this http://carbon.nesbot.com/docs/

<code>$dt = Carbon::now()->dayOfWeek;
// $dt = 0 ~ 6</code>

Note: Sunday returns 0

<code>echo (new Carbon('20160628'))->dayOfYear;</code>

Carbon is very flexible. It is recommended to look at the source code. There are many, many methods

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn