Jump to content

[SOLVED] unix timestamp


phorcon3

Recommended Posts

<?php

$timestamp = time();

?>

 

and let's say this equals to 1202482743

 

<?php

echo date('F j, Y @ g:i A', 1202482743);

?>

 

which then equals to February 8, 2008 @ 3:59 PM

 

but how could i transform the unix timestamp (1202482743) so it would output February 8, 2008 @ 12:00 AM ..so it's the beginning of the day?

 

i can only think of a really stupid way to do it, and that would be it

 

<?php

$timestamp = time();

$month = date('n', $timestamp);
$day = date('j', $timestamp);
$year = date('Y', $timestamp);

echo date('F j, Y @ g:i A', mktime(0,0,0,$month,$day,$year));

?>

 

can anyone else think of a better way to do it?

Link to comment
https://forums.phpfreaks.com/topic/90060-solved-unix-timestamp/
Share on other sites

simple

convert timestamp to date string without time portion so it's a date, convert this into a timestamp. (this can be done initially as well, so timestamp never has the time information).

 

<?php
$timestamp = 1202482743;
$startofday = strtotime(date("Y-m-d",$timestamp));
echo date('F j, Y @ g:i A',$startofday);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/90060-solved-unix-timestamp/#findComment-461906
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.