Skip to content
Advertisement

Datetime to Timestamp in milliseconds in PHP

I would like to create a timestamp in milliseconds from the input ‘2016-03-22 14:30’. Also the timezone specified should be Australia/Sydney.

I’ve tried different approaches but none seem to be working.

Can anyone help me please? I’m really struggling with that.

Advertisement

Answer

Pretty self explanatory code, so I wont say much.

date_default_timezone_set('Australia/Sydney'); // set timezone
$yourdate = '2016-03-22 14:30';
$stamp = strtotime($yourdate); // get unix timestamp
$time_in_ms = $stamp*1000;

If you want to display it properly.

echo number_format($time_in_ms, 0, '.', '');
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement