I am trying to get the current timestamp using Carbon or DateTime Class I get wrong date but when I use date() function it return the correct date I run the code on win server 2012 this is my code
dd([
'Carbon::now()->format("Y-m-d H:i:s P")' => Illuminate\Support\Carbon::now()->format('Y-m-d H:i:s P'),
'DateTime()->format("Y-m-d H:i:s P")' => (new DateTime())->format('Y-m-d H:i:s P'),
'date("Y-m-d H:i:s P")' => date('Y-m-d H:i:s P'),
'date("Y-m-d H:i:s P",microtime(true))' => date("Y-m-d H:i:s P", microtime(true)),
'date("Y-m-d H:i:s P", time())' => date("Y-m-d H:i:s P", time()),
'Carbon::now()->getTimestamp()' => Illuminate\Support\Carbon::now()->getTimestamp(),
'microtime()' => microtime(true),
'time()' => time(),
]);
this is the output that I got
[
"Carbon::now()->format("Y-m-d H:i:s P")" => "2018-06-25 22:41:59 +03:00"
"DateTime()->format("Y-m-d H:i:s P")" => "2018-06-25 22:41:59 +03:00"
"date("Y-m-d H:i:s P")" => "2018-06-19 11:59:22 +03:00"
"date("Y-m-d H:i:s P",microtime(true))" => "2018-06-25 22:41:59 +03:00"
"date("Y-m-d H:i:s P", time())" => "2018-06-19 11:59:22 +03:00"
"Carbon::now()->getTimestamp()" => 1529955719
"microtime()" => 1529955719.4257
"time()" => 1529398762
]
the server time is the same as the value of date function
$dt = Carbon::now();
and then useCarbon::createFromFormat('Y-m-d H', $dt)->toDateTimeString();
– Rubicund"Y-m-d H:i:s P"
without the P, i.e."Y-m-d H:i:s"
– Rubicunddate("Y-m-d H:i:s P", microtime(true))
returns exact time DateTime() does. Is it wrong? – Erethism