카테고리 없음

Carbon 라이브러리 날짜, 요일 표기 (shortDayName, format, lastOfMonth, endOfMonth)

Sein_ 2024. 5. 8. 16:32
728x90
//2024-05-13 00:00:00
$startDay = \Carbon\Carbon::parse($booking_row->start_day); 

$startDay->toDateString(); //2024-05-13
$startDay->shortDayName; //월
$startDay->format('H:i'); // 20:15

 

  • shortDayName : short name of weekday translated according to Carbon locale (한국: 월)

 

  • lastOfMonth() : 그 달의 마지막 날이 시작된 순간을 얻을 수 있다 (00:00:00)
  • endOfMonth() : 그 달의 마지막 날이 끝나는 순간을 얻을 수 있다 (23:59:59)
>>> echo today()->lastOfMonth();
2019-10-31 00:00:00
>>> echo today()->endOfMonth();
2019-10-31 23:59:59

 

  • firstOfMonth() : 그 달의 첫날이 시작된 순간을 얻을 수 있다 (00:00:00)
  • startOfMonth() : 그 달의 첫날이 시작된 순간을 얻을 수 있다 (00:00:00)

(동일)

>>> echo today()->firstOfMonth();
2019-10-01 00:00:00
>>> echo today()->startOfMonth();
2019-10-01 00:00:00

 

  • startOfDay() : 그 날이 시작된 순간을 얻을 수 있다 (00:00:00)
  • endOfDay() : 그 날이 끝나는 순간을 얻을 수 있다 (23:59:59)
>>> echo today()->startOfDay();
2019-10-17 00:00:00
>>> echo today()->endOfDay();
2019-10-17 23:59:59

 

 

 

이외

$dt = Carbon::parse('2012-10-5 23:26:11.123789');

// These getters specifically return integers, ie intval()
var_dump($dt->year);                                         // int(2012)
var_dump($dt->month);                                        // int(10)
var_dump($dt->day);                                          // int(5)
var_dump($dt->hour);                                         // int(23)
var_dump($dt->minute);                                       // int(26)
var_dump($dt->second);                                       // int(11)
var_dump($dt->micro);                                        // int(123789)
// dayOfWeek returns a number between 0 (sunday) and 6 (saturday)
var_dump($dt->dayOfWeek);                                    // int(5)
// dayOfWeekIso returns a number between 1 (monday) and 7 (sunday)
var_dump($dt->dayOfWeekIso);                                 // int(5)
var_dump($dt->englishDayOfWeek);                             // string(6) "Friday"
var_dump($dt->shortEnglishDayOfWeek);                        // string(3) "Fri"
var_dump($dt->locale('de')->dayName);                        // string(7) "Freitag"
var_dump($dt->locale('de')->shortDayName);                   // string(3) "Fr."
var_dump($dt->locale('de')->minDayName);                     // string(2) "Fr"
var_dump($dt->englishMonth);                                 // string(7) "October"
var_dump($dt->shortEnglishMonth);                            // string(3) "Oct"
var_dump($dt->locale('de')->monthName);                      // string(7) "Oktober"
var_dump($dt->locale('de')->shortMonthName);                 // string(3) "Okt"

var_dump($dt->dayOfYear);                                    // int(279)
var_dump($dt->weekNumberInMonth);                            // int(1)
// weekNumberInMonth consider weeks from monday to sunday, so the week 1 will
// contain 1 day if the month start with a sunday, and up to 7 if it starts with a monday
var_dump($dt->weekOfMonth);                                  // int(1)
// weekOfMonth will returns 1 for the 7 first days of the month, then 2 from the 8th to
// the 14th, 3 from the 15th to the 21st, 4 from 22nd to 28th and 5 above
var_dump($dt->weekOfYear);                                   // int(40)
var_dump($dt->daysInMonth);                                  // int(31)
var_dump($dt->timestamp);                                    // int(1349479571)
var_dump($dt->getTimestamp());                               // int(1349479571)
// Millisecond-precise timestamp as int
var_dump($dt->getTimestampMs());                             // int(1349479571124)
// Millisecond-precise timestamp as float (useful to pass it to JavaScript)
var_dump($dt->valueOf());                                    // float(1349479571124)
// Custom-precision timestamp
var_dump($dt->getPreciseTimestamp(6));                       // float(1349479571123789)
var_dump(Carbon::createFromDate(1975, 5, 21)->age);          // int(48) calculated vs now in the same tz

 

 

 

 

 

 

https://qiita.com/avocadoneko/items/0e05d39b55eeba12e89c

 

Carbon の lastOfMonth() と endOfMonth() の違い - Qiita

会社のコードの中で、lastOfMonth() と endOfMonth() が混在していた。何が違うのか調べてもまとまっている記事がなかったので書く。調査にはLaravelのTinkerを使った。…

qiita.com

https://carbon.nesbot.com/docs/

 

Carbon - A simple PHP API extension for DateTime.

You can see from the code snippet above that the Carbon class is declared in the Carbon namespace. You need to import the namespace to use Carbon without having to provide its fully qualified name each time. Examples in this documentation will assume you i

carbon.nesbot.com