QKWS
QKWS

Reputation: 1109

How to get system time in PHP?

I am trying to get this output:

2013072708410102

which is year/month/day/hour/minutes/seconds/milliseconds.

I tried this:

$getDate = date("Ymd");
$getTime = time();

echo $getDate . " " . $getTime;

I am getting this kind of output:

201307271374885743 

The year/month/day is correct. But I dont think its giving me the time format that I wanted.

How can I have this format 2013072708410102 year/month/day/hour/minutes/seconds/milliseconds?

Upvotes: 0

Views: 223

Answers (1)

bwoebi
bwoebi

Reputation: 23777

echo date("YmdHis").str_pad((int)((($time = microtime(1)) - (int)$time) * 1000), 3, "0", STR_PAD_LEFT);

gives: 20130727024937671 to me, what should what you expect.

date("YmdHis") gives the year/month/day/hour/minutes/seconds part.

str_pad((int)((($time = microtime(1)) - (int)$time) * 1000), 3, "0", STR_PAD_LEFT) is for the milliseconds.

Upvotes: 2

Related Questions