Reputation:
I have a problem in extracting time from $timestamp
which something looks like
this $timestamp = "2017-05-03 11:47:48";
my question is: how to extract time from above $timestamp
like this 11:47 AM
my current time zone is Asia/Kolkata
Upvotes: 3
Views: 5224
Reputation: 26258
First of all this
$timestamp = "2017-05-03 11:47:48";
is not timestamp
, Its a date time value in some specific format. To change it to your required format you can try following code in Php:
echo date('H:i A', strtotime($timestamp));
here H
is used for 24 Hour format, use h
for 12 hours format.
Upvotes: 0
Reputation: 28529
First make sure you installed carbon, refer to https://github.com/briannesbitt/Carbon.
$timestamp = "2017-05-03 11:47:48";
$date = Carbon::createFromFormat('Y-m-d H:i:s', '2017-05-03 11:47:48', 'Asia/Kolkata');
echo $date->format("H:i A");
Upvotes: 2
Reputation: 15141
Hope this will help you out.
<?php
ini_set('display_errors', 1);
$timestamp = "2017-05-03 11:47:48";
$dateObj=date_create_from_format("Y-m-d H:i:s", $timestamp);
echo $dateObj->format("H:i A");
Output:
11:47 AM
Upvotes: -1