carbon formatting carbon format

Solutions on MaxInterview for carbon formatting carbon format by the best coders in the world

showing results for - "carbon formatting carbon format"
Sofie
25 Sep 2020
1$dt = Carbon::create(1975, 12, 25, 14, 15, 16);
2
3var_dump($dt->toDateTimeString() == $dt);          // bool(true) => uses __toString()
4echo $dt->toDateString();                          // 1975-12-25
5echo $dt->toFormattedDateString();                 // Dec 25, 1975
6echo $dt->toTimeString();                          // 14:15:16
7echo $dt->toDateTimeString();                      // 1975-12-25 14:15:16
8echo $dt->toDayDateTimeString();                   // Thu, Dec 25, 1975 2:15 PM
9
10// ... of course format() is still available
11echo $dt->format('l jS \\of F Y h:i:s A');         // Thursday 25th of December 1975 02:15:16 PM
12
13// The reverse hasFormat method allows you to test if a string looks like a given format
14var_dump(Carbon::hasFormat('Thursday 25th December 1975 02:15:16 PM', 'l jS F Y h:i:s A')); // bool(true)
15