
IntlGregorianCalendar::createFromDate 메소드는 새로운 IntlGregorianCalendar 객체를 반환하는 이유는 메소드의 이름 자체에서 알 수 있습니다. createFromDate는 새로운 객체를 생성하는 메소드이기 때문입니다.
새로운 객체를 반환하는 대신, 기존의 $calendar 객체에 날짜와 시간을 설정하고 싶다면 set(int $year, int $month, int $day) 메소드를 사용할 수 있습니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$calendar = new IntlGregorianCalendar();
$calendar->set(2022, 9, 1);
이렇게 설정된 날짜와 시간을 가져오려면 getTime() 메소드를 사용할 수 있습니다.
#hostingforum.kr
php
$calendar = new IntlGregorianCalendar();
$calendar->set(2022, 9, 1);
$time = $calendar->getTime();
getTime() 메소드는 DateTime 객체를 반환하므로, DateTime 클래스의 메소드를 사용하여 날짜와 시간을 가져올 수 있습니다.
#hostingforum.kr
php
$calendar = new IntlGregorianCalendar();
$calendar->set(2022, 9, 1);
$time = $calendar->getTime();
echo $time->format('Y-m-d H:i:s'); // 2022-09-01 00:00:00
2025-03-23 06:07