DateTime 클래스
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
소개
이 클래스는 DateTime::modify()와 같은 수정 메서드가 호출될 때 객체 자체가 수정된다는 점을 제외하고 DateTimeImmutable과 동일하게 동작합니다.
클래스 개요
class DateTime implements DateTimeInterface {
/* Inherited constants */
const string DateTimeInterface::ATOM = "Y-m-d\TH:i:sP";
const string DateTimeInterface::COOKIE = "l, d-M-Y H:i:s T";
const string DateTimeInterface::ISO8601 = "Y-m-d\TH:i:sO";
const string DateTimeInterface::RFC822 = "D, d M y H:i:s O";
const string DateTimeInterface::RFC850 = "l, d-M-y H:i:s T";
const string DateTimeInterface::RFC1036 = "D, d M y H:i:s O";
const string DateTimeInterface::RFC1123 = "D, d M Y H:i:s O";
const string DateTimeInterface::RFC7231 = "D, d M Y H:i:s \G\M\T";
const string DateTimeInterface::RFC2822 = "D, d M Y H:i:s O";
const string DateTimeInterface::RFC3339 = "Y-m-d\TH:i:sP";
const string DateTimeInterface::RFC3339_EXTENDED = "Y-m-d\TH:i:s.vP";
const string DateTimeInterface::RSS = "D, d M Y H:i:s O";
const string DateTimeInterface::W3C = "Y-m-d\TH:i:sP";
/* Methods */
public __construct(string $datetime = "now", ?DateTimeZone $timezone = null)
public add(DateInterval $interval): DateTime
public static createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false
public static createFromImmutable(DateTimeImmutable $object): DateTime
public static createFromInterface(DateTimeInterface $object): DateTime
public static getLastErrors(): array|false
public modify(string $modifier): DateTime|false
public static __set_state(array $array): DateTime
public setDate(int $year, int $month, int $day): DateTime
public setISODate(int $year, int $week, int $dayOfWeek = 1): DateTime
public setTime(
int $hour,
int $minute,
int $second = 0,
int $microsecond = 0
): DateTime
public setTimestamp(int $timestamp): DateTime
public setTimezone(DateTimeZone $timezone): DateTime
public sub(DateInterval $interval): DateTime
public diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval
public format(string $format): string
public getOffset(): int
public getTimestamp(): int
public getTimezone(): DateTimeZone|false
public __wakeup(): void
}
변경 로그
버전 | 설명 |
---|---|
7.2.0 | DateTime의 클래스 상수는 이제 DateTimeInterface에 정의됩니다. |
목차
- DateTime::add — DateTime 객체에 일, 월, 년, 시, 분, 초를 추가합니다.
- DateTime::__construct — 새 DateTime 객체를 반환합니다.
- DateTime::createFromFormat — 지정된 형식에 따라 시간 문자열을 구문 분석합니다.
- DateTime::createFromImmutable — 주어진 DateTimeImmutable 객체를 캡슐화하는 새로운 DateTime 객체를 반환합니다.
- DateTime::createFromInterface — 주어진 DateTimeInterface 객체를 캡슐화하는 새로운 DateTime 객체를 반환합니다.
- DateTime::getLastErrors — 경고 및 오류를 반환합니다.
- DateTime::modify — 타임스탬프 변경
- DateTime::__set_state — __set_state 핸들러
- DateTime::setDate — 날짜를 설정합니다
- DateTime::setISODate — ISO 날짜를 설정합니다.
- DateTime::setTime — 시간을 설정합니다
- DateTime::setTimestamp — Unix 타임스탬프를 기반으로 날짜와 시간을 설정합니다.
- DateTime::setTimezone — DateTime 객체의 시간대를 설정합니다.
- DateTime::sub — ateTime 객체에서 일, 월, 년, 시, 분, 초의 양을 뺍니다.