<?php
function date_to_unix($date){
// converts 20140526 - 1401062400
$date = DateTime::createFromFormat('Ymd', $date);
return (int) $date->format('U');
}
function unix_to_date($unix){
// converts 1401062400 - 20140526
$date = DateTime::createFromFormat('U', $unix);
return (int) $date->format('Ymd');
}
$date = date("Ymd");
echo "date $date\n"; // date 20140525
$time = time();
echo "time $time\n"; // time 1401069030
$unix = date_to_unix($date);
echo "unix $unix\n"; // unix 1401069030
$date = unix_to_date($unix);
echo "date $date\n"; // date 20140526
- Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
- date 20140526
time 1401085851
unix 1401085851
date 20140526
- Output for 5.2.10 - 5.2.17
- date 20140526
time 1401085851
Fatal error: Call to undefined method DateTime::createFromFormat() in /in/irF0o on line 4
Process exited with code 255. - Output for 5.2.0 - 5.2.9
- date 20140526
time 1401085851
Fatal error: Call to undefined method DateTime::createfromformat() in /in/irF0o on line 4
Process exited with code 255. - Output for 5.0.0 - 5.0.5, 5.1.1 - 5.1.6
- date 20140526
time 1401085851
Fatal error: Class 'DateTime' not found in /in/irF0o on line 4
Process exited with code 255. - Output for 5.1.0
- Fatal error: fatal flex scanner internal error--end of buffer missed in /in/irF0o on line 24
Process exited with code 255. - Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
- date 20140526
time 1401085851
Fatal error: Undefined class name 'datetime' in /in/irF0o on line 4
Process exited with code 255. - Output for 4.3.0 - 4.3.1
- date 20140526
time 1401085851
Fatal error: Undefined class name 'datetime' in /in/irF0o on line 4
preferences:
170.08 ms | 401 KiB | 233 Q