Doubt about php date format

0

I want to print a current date in php, but I'm not sure what format it has, the example I should follow is this: "1985-04-12T23: 20: 50.52Z"

    
asked by David Espinal 23.08.2017 в 00:42
source

4 answers

1

The format you show is UTC (Coordinated Universal Time), with a designator UTC special Z (Zulu).

You can use the class DateTime :

echo ( new DateTime() )->format('Y-m-d\TH:i:s\Z'); // 2017-08-23T03:25:06Z

Watch Online

    
answered by 23.08.2017 / 12:27
source
0

The format you are looking for is ISO 8601

You can show the current date in that format in the following way

<?php
echo date('c');

Result:

2017-08-23T02:02:30+02:00

You can find more information at date () and at ISO 8601

    
answered by 23.08.2017 в 02:09
0

I do not know if it's late but I'm also in the development of electronic invoicing and this worked for me. Source: link

$ahora = DateTime::createFromFormat('U.u', number_format(microtime(true), 3, '.', ''));
$local = $ahora->setTimeZone(new DateTimeZone('America/Bogota'));
$formateado = $local->format("Y-m-d H:i:s.u");
$fecha = substr($formateado, 0, -3).'Z';
    
answered by 26.07.2018 в 15:42
0

I know a simpler way to print the current date and time:

    $Ahora = date("Y-m-d H:i:s");
    echo $Ahora;

You decide in what format you want it playing with the parameters "Y-m-d H: i: s"

    
answered by 23.08.2017 в 01:07