tereglow Posted June 6, 2007 Share Posted June 6, 2007 Hello, I was wondering if someone could point me in the right direction to do some date conversions. What I need is to be able to convert a standard date (i.e. 2007-06-01 23:33) to epoch in milliseconds, and vice versa. With Perl, I've used the TimeDate::Format::Epoch CPAN module; am looking for similar functionality in PHP. Best Regards, Tom Link to comment https://forums.phpfreaks.com/topic/54466-solved-converting-epoch-format/ Share on other sites More sharing options...
leap500 Posted June 6, 2007 Share Posted June 6, 2007 Hi Tom Try this: <?php $day = 6; $month = 6; $year = 2007; $hour = 22; $minute = 12; $second = 15; $timestamp = mktime($hour, $minute, $second, $month, $day, $year); $date = date('Y-m-d H:m', $timestamp); echo $timestamp . '<br />'; echo $date; ?> If you need microseconds, have a look at http://www.php.net/manual/en/function.microtime.php Link to comment https://forums.phpfreaks.com/topic/54466-solved-converting-epoch-format/#findComment-269547 Share on other sites More sharing options...
leap500 Posted June 6, 2007 Share Posted June 6, 2007 you could also use: <?php $timestamp = mktime(date('H'), date('m'), date('s'), date('m'), date('d'), date('Y')); $date = date('Y-m-d H:m', $timestamp); echo $timestamp . '<br />'; echo $date; ?> Link to comment https://forums.phpfreaks.com/topic/54466-solved-converting-epoch-format/#findComment-269548 Share on other sites More sharing options...
tereglow Posted June 7, 2007 Author Share Posted June 7, 2007 Thanks for all of the help. I was able to do this via the following: <?php # Convert Epoch in Milliseconds to Seconds $epoch=1171391881904*.001; # Convert Epoch in Seconds to an Associate Array using getdate $t = getdate($epoch); # Print out the desired format using the elements in the array. print $t['mon']."/".$t['mday']."/".$t['year']." ".$t['hours'].":".$t['minutes']; ?> Thanks again. Tom Link to comment https://forums.phpfreaks.com/topic/54466-solved-converting-epoch-format/#findComment-270028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.