2016-05-13 10 views
2

document page of Carbon libraryから、単純な単語を使用してCarbonオブジェクトを初期化することが可能であると述べられています。例えば、Carbon::parse('first day of December 2008')またはしかしPHPのCarbonを使用する場合、今月のn日目に日付を設定するにはどうすればいいですか?

new Carbon('first day of December 2008')、私はこれらのすべてが失敗し、次の試行

Carbon::parse('10th day of this month') 
Carbon::parse('tenth day of this month') 
Carbon::parse('10th of this month') 
Carbon::parse('tenth of this month') 
Carbon::parse('10 of this month') 
Carbon::parse('ten of this month') 

で今月の10日に日付を設定しようとしています。

現在、希望のCarbonオブジェクトをCarbon::parse('first day of this month')->addDays(9)で作成することはできますが、読みやすさは良くありません。より多くのコードを読み込む必要があり、最初の釉薬で今月9日と誤解するのは非常に簡単です。

したがって、1つの解析だけでCarbonオブジェクトを作成する方法はありますか?

答えて

2

それは少し醜いですが、これは

Carbon::parse('10th ' . date('M')); 
+0

悪い、と私の現在のソリューションよりも少なくとも良いとは限りません動作するはずです。私がこれを最善の答えとして受け入れる前に、もっと良い答えがあるかどうか少し調べる必要があります。 – cytsunny

関連する問題