Tarih ve Saat

Nette\Utils\DateTime yerel DateTime adresini genişleten bir sınıftır.

Kurulum:

composer require nette/utils

Tüm örnekler aşağıdaki sınıf takma adının tanımlandığını varsayar:

use Nette\Utils\DateTime;

static from(string|int|\DateTimeInterface $time): DateTime

Bir dizeden, UNIX zaman damgasından veya başka bir DateTimeInterface nesnesinden DateTime nesnesi oluşturur. Tarih ve saat geçerli değilse Exception adresini atar.

DateTime::from(1138013640); // creates a DateTime from the UNIX timestamp with a default timezamp
DateTime::from(42); // creates a DateTime from the current time plus 42 seconds
DateTime::from('1994-02-26 04:15:32'); // creates a DateTime based on a string
DateTime::from('1994-02-26'); // create DateTime by date, time will be 00:00:00

static fromParts(int $year, int $month, int $day, int $hour=0, int $minute=0, float $second=0.0): DateTime

DateTime nesnesini oluşturur veya tarih ve saat geçerli değilse bir Nette\InvalidArgumentException istisnası atar.

DateTime::fromParts(1994, 2, 26, 4, 15, 32);

static createFromFormat(string $format, string $time, string|\DateTimeZone $timezone=null): DateTime|false

DateTime::createFromFormat() işlevini, bir zaman dilimini dize olarak belirtme özelliğiyle genişletir.

DateTime::createFromFormat('d.m.Y', '26.02.1994', 'Europe/London'); // create with custom timezone

modifyClone(string $modify='')static

Değiştirilmiş zamana sahip bir kopya oluşturur.

$original = DateTime::from('2017-02-03');
$clone = $original->modifyClone('+1 day');
$original->format('Y-m-d'); // '2017-02-03'
$clone->format('Y-m-d');    // '2017-02-04'

__toString(): string

Tarih ve saati Y-m-d H:i:s biçiminde döndürür.

echo $dateTime; // '2017-02-03 04:15:32'

Implements JsonSerializable

Tarih ve saati, örneğin JavaScript'te kullanılan ISO 8601 biçiminde döndürür.

$date = DateTime::from('2017-02-03');
echo json_encode($date);
versiyon: 4.0