I am using php and kohana framework.Below is the php code i am using to show the date and time.
$message_date = date('Y-m-d', strtotime($message->last_modified_date));
$current_date = date('Y-m-d');
$yesterday = date("Y-m-d", strtotime("yesterday"));
if ($message_date == $current_date):
$date = "Today at " . date('h:i A', strtotime($message->last_modified_date));
elseif ($message_date == $yesterday):
$date = "Yesterday";
else:
$date = date("M d, Y", strtotime($message->last_modified_date));
endif;
<span class="msg-date"><?= $date; ?></span>
Update: my own tried solution
$tz = new DateTimeZone('America/Chicago');
$message_date = new DateTime($message_date);
$message_date->setTimeZone($tz);
$messagedate = $message_date->format('Y-m-d H:i:s');//converted time
I need to localize the time depends on the local machine the user is using.If the user viewing my page from "India" the time should adjust with Indian time,if the same page is viewed in USA or UK,the time should adjusted with USA or UK.
How can i do this in kohana or php.