Saturday, September 1, 2012

How to convert milliseconds to date format in PHP

Normally date field is stored in database as timestamps format, the number of seconds since 00:00:00 UTC on January 1, 1970. Some times the date represented as the number of milliseconds.

There is no default function available in PHP to convert this milliseconds representation to human readable format. In PHP date function is used for converting timestamp format to local date/time format.

This following PHP function will convert milliseconds format to local date format

$milliseconds =  1340562600000;
$timestamp = $milliseconds/1000;
echo date("d-m-Y", $timestamp);

output = 25-06-2012

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Maintained by Web Themes