2

Mktime and other functions give wrong answer for such a date like 2011-02-27 02:04:46;

good_evening
  • 21,085
  • 65
  • 193
  • 298

3 Answers3

10

Just use the strtotime() function, or the DateTime class.


Both the two following portions of code :

echo strtotime('2011-02-27 02:04:46');

$dt = new DateTime('2011-02-27 02:04:46');
echo $dt->format('U');

Will give you the same output :

1298768686
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
2

Use strtotime

$time = '2011-02-27 02:04:46';
strtotime($time);
bland_dan
  • 448
  • 3
  • 8
  • 19
  • 2
    Why the date() call? strtotime already returns a PHP time value, which is a unix timestamp. – Marc B Apr 21 '11 at 20:18
  • 1
    my bad, just copied and pasted from a script where I'd used strtotime to convert from one time format to another (not UNIX) – bland_dan Apr 21 '11 at 20:21
1

This will also work (if you need this to run from the unix shell):

date +%T

This will show the time like:

14:20:18
dvanaria
  • 6,593
  • 22
  • 62
  • 82