- mt_rand: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- sprintf: documentation ( source)
<?php
$dt = new DateTime();
$dstr = $dt->format('Y-m-d H:i:s.u');
$darr = explode(".", $dstr) ;
$darr[1] = sprintf("%6d", mt_rand(0, 999999)) ;
$dstr = implode(".", $darr) ;
echo $dstr . "\n";
$dn = DateTime::createFromFormat('Y-m-d H:i:s.u', $dstr);
echo $dn->format('U.u') . "\n";