Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get time from timestamp using carbon php

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


1 Answers

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");
like image 59
LF00 Avatar answered Mar 15 '26 05:03

LF00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!