How to create a string equivalent to yyyyMMddHHmmssffff in PHP?
P粉238355860
P粉238355860 2023-07-31 12:10:17
0
1
514
<p>I'm trying to integrate with some VB code that uses DateTime.Now.ToString("yyyyMMddHHmmssffff") to generate a string. </p> <p><code>DateTime.Now.ToString("yyyyMMddHHmmssffff")</code></p> <p>The closest I can get to this in PHP is: </p> <p><code>date('YmdHis')</code></p> <p>But this is missing the millisecond part. </p><p>I have tried using microtime, for example: </p><p><code></code></p> <p><code>date('YmdHis',time()).substr(str_replace(".","",microtime(true)),10,17)</code></p> <p>But sometimes this results in a shorter string. </p>
P粉238355860
P粉238355860

reply all(1)
P粉978551081

date The function always returns zero for microseconds. You can use the DateTime->format function and remove the last two digits to retain 4 decimal places.

substr((new DateTime()) -> format('YmdHisu'), 0, 18);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template