Jump to content

Recommended Posts

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

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

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.