I'm trying to get a unix timestamp with PHP but it doesn't seem to be working. Here is the format I'm trying to convert to a unix timestamp:
PHP
$datetime = '2012-07-25 14:35:08';
$unix_time = date('Ymdhis', strtotime($datetime ));
echo $unix_time;
My result looks like this:
20120725023508
Any idea what I'm doing wrong?
Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch.
You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.
To find the unix current timestamp use the %s option in the date command. The %s option calculates unix timestamp by finding the number of seconds between the current date and unix epoch.
strtotime Returns a timestamp
on success, FALSE otherwise.
echo strtotime('2012-07-25 14:35:08' );
Output
1343219708
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With