0

How to produce this kind of date string in PHP ? this sample date string below is coming from a postgresql output

2020-10-20 14:44:37.060966+08

I already tried something like

date('Y-m-d H:i:sO',strtotime('now'));

and

date('Y-m-d H:i:sOT',strtotime('now'));

but still i cannot produce the part starting from the decimal point to the end of my sample string.. so how to generate that format with decimal and + something something right after the seconds in PHP ?

sasori
  • 5,249
  • 16
  • 86
  • 138

1 Answers1

0

That part is microsecond, you can use this format Y-m-d H:i:s.uO to add microsecond.

One thing to note that microsecond format with date() will always be 000000. Use DateTime::format() instead:

$date = new DateTime();
echo $date->format('Y-m-d H:i:s.uO');

Output:

2020-12-07 03:17:37.011493+0100
catcon
  • 1,295
  • 1
  • 9
  • 18