“Datetime ISO 8601 PHP” Réponses codées

PHP convertit la date et l'heure à ISO 8601

//Object Oriented Method

$datetime = new DateTime('2010-12-30 23:21:46');

echo $datetime->format(DateTime::ATOM); // Updated ISO8601


//Procedural Method

echo date(DATE_ISO8601, strtotime('2010-12-30 23:21:46'));
Disturbed Dugong

Datetime ISO 8601 PHP

(new DateTime('2022-05-01T16:00:00-03:00'))->format('Y-m-d\TH:i:sp');
Tiago F2

format datetime iso php

$startTime 	= new DateTime($appointment_date . ' ' . $booking_slot[0]); // 2021-12-28 0900
$startTime	= $startTime->format('Y-m-d\TH:i:sp'); // 2021-12-25T12:02:00Z
Strange Squirrel

ISO 8601 PHP


FYI: there's a list of constants with predefined formats on the DateTime object, for example instead of outputting ISO 8601 dates with:

<?php
echo date('c');
?>

or

<?php
echo date('Y-m-d\TH:i:sO');
?>

You can use

<?php
echo date(DateTime::ISO8601);
?>

instead, which is much easier to read.
Dev

Réponses similaires à “Datetime ISO 8601 PHP”

Questions similaires à “Datetime ISO 8601 PHP”

Plus de réponses similaires à “Datetime ISO 8601 PHP” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code