how to get local date from timestamp = 1574463600 in php mysql [duplicate] - php

This question already has answers here:
Convert timestamp to readable date/time PHP
(14 answers)
Closed 3 years ago.
i am using sports api and i am getting matches schedule from api but the timestamp is UTC and i want to search match according to my localdate the timestamp is look like this 1574463600

You can use # along with the unix time to create a DateTime class.
<?php
$unixTime = 1574463600;
$date = new DateTime('#' . $unixTime);
echo $date->format('d/m/Y'); // outputs 22/11/2019
See it here https://3v4l.org/eoSU9
Read about DateTime here https://www.php.net/manual/en/class.datetime

Related

Need to change my date format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I change the format of my date from 2016-10-05 to 10/05/2016 in php
$date= $row['date'];
So when the row echos out it'll all be the new format
Use DateTime to create an object (from the current format), allowing you to reformat the output.
$date = "2016-10-05";
$date = DateTime::createFromFormat('Y-d-m', $date);
echo $date->format('d/m/Y');
https://repl.it/DqvO

Convert date in PHP from number to date [duplicate]

This question already has answers here:
DateTime->format(epoch) returning the wrong date
(4 answers)
Closed 7 years ago.
How do I convert this date: 1427510741 to: 2015-03-22 09:27:02 in PHP?
I tried: $date2 = new DateTime($date1);
but it gives me: 0741-04-08
And I want this: 2015-03-22 09:27:02
You're close. To use a Unix Timestamp with DateTime to must prepend an # before the timestamp:
$date2 = new DateTime('#'.$date1);
Demo

Convert output to a readable time [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
Well, I am working with twitch's API currently and I want to echo the time that the current stream started at. Currently the following is output: 2015-04-11T07:45:20Z seconds so I am wondering how I would convert this into a readable time. i.e. 07:45:20.
DateTime::createFromFormat() allows you to read in non-standard date input and turn it into a DateTime object that you can then use to format your output however you like:
$date = DateTime::createFromFormat('Y-m-d\TH:i:s\Z *', '2015-04-11T07:45:20Z seconds');
echo $date->format('H:i:s'); // 07:45:20
Demo

Time Format : PHP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Covert time format in php
I am getting a start_time field value from mysql data base as 2012-08-14 21:30:00
and i want to convert it in php format like 2012-08-14T09:30 is there any method to do
this in php ?
use strtotime()
$date = strtotime('2012-08-14 21:30:00');
echo date('Y-m-d\Th:i',$date);
see this example.for the required date & time format:
$date=date("Y-m-d H:i:s");//get the current date
$d=strtotime($date);//convert in strtotime
echo $final_date=date("Y-m-d\Th:i:s",$d);//in the first argument of date ,put the format whatever you want,but be sure to convert it in strtotime first.

Convert unix timestamp [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to convert Unix timestamp to hhmmss?
Here is unix timestamp of today
1306702800
How to convert it to look like 30-05-2011 using php ?
You can use the date function to convert (and arbitrarily re-format) timestamps as such:
echo date('d-m-Y', 1306702800);
Additionally, you can get the current timestamp via the time function, so you could output the current date via: echo date('d-m-Y', time());.
Use PHP's date functions: http://nl3.php.net/manual/en/function.date.php
See date
echo date('d-m-Y', '%your-time-stamp%');

Categories