Can anyone help , i want to to make simple script as anyone insert human date like 2013 - 9 - 25 19:10:00 P.M to milliseconds Unix .
is it possible using strtotime.
I want anyone to show me how to make the whole human date (2013 - 9 - 25 19:10:00 P.M ) be in one variable so i can convert it then echo it
You can use strtotime or timestamp
timestamp example
$dt = new DateTime("Fri Dec 18 2013 14:25:00 GMT-0600 (MST)");
$ts = $dt->getTimestamp();
Strtotime example
$ts = strtotime("Fri Dec 09 2013 14:25:00 GMT-0600 (MST)");
echo date("r", $ts);
In your case:
$timestamp = strtotime('2013-9-25 19:10:00 P.M');
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
Need a little help.
I'm using PHP.
Here is a example date:
Mon Sep 05 2016 15:30:00 GMT+0800 (China Standard Time)
What i want is display a outpout like this:
2016-09-05 15:30:00
I've tried to convert it using this function:
date('Y-m-d h:i:s', strtotime($time));
But the output is:
1970-01-01 08:00:00
Need some advice
Thanks.
Just use DateTime():
$time = 'Mon Sep 05 2016 15:30:00 GMT+0800';
$date = new DateTime($time);
echo $date->format('Y-m-d H:i:s');
<?php
$timezone = -5; //(GMT -5:00) EST (U.S. & Canada)
echo gmdate("Y-m-j H:i:s", time() + 3600*($timezone+date("I")));
?>
This doc would help more
http://php.net/manual/en/function.gmdate.php
$date=date_create("Mon Sep 05 2016 15:30:00 GMT+0800");
echo date_format($date,"Y/m/d H:i:s");
This string 2016-09-13 08:56:55 +0000 - What is the time zone?
How do convert PDT time format Wed Oct 12 14:40:50 PDT 2016 to this foramt 2016-09-13 08:56:55 +0000.
I am try:
$input_datetime = 'Wed Oct 12 14:40:50 PDT 2016';
$result_datetime = date('Y-m-d H:i:s',strtotime($input_datetime)) . ' +0000';
echo $result_datetime; // 2016-10-12 14:40:50 +0000
I don't know about timezones. Just I'm making the datetime format.
Please update the solutions or suggest.
Thanks for every one!
Your expected output does not make sense to me, because line nogad mentioned, the seconds and minutes change. Please clarify. Meanwhile here the conversion format you wanted:
$datestr = 'Wed Oct 12 14:40:50 PDT 2016';
$dt = new DateTime($datestr);
echo $dt->format("Y-m-d\ H:i:s O");
Output is:
2016-10-12 14:40:50 -0700
I am working on a PHP file were I am pulling in timestamps from a database that come out as
Tue Sep 22 16:11:12 EDT 2015
Mon Nov 16 07:42:31 EST 2015
I was wondering how to convert dates of this format into unix time format.
You can use the DateTime object
$dateTime = new DateTime('Tue Sep 22 16:11:12 EDT 2015');
echo $dateTime->getTimestamp();
The result would be 1442952672
If you look at the PHP manual for \DateTime::createFromFormat() or date(), you will find tables of codes accepted by \DateTime::createFromFormat(). Looking at them you will see that you need the following:-
$date = \DateTime::createFromFormat('D M d H:i:s T Y', 'Tue Sep 22 16:11:12 EDT 2015');
echo $date->getTimestamp();
Demo.
The 'd' in the format string may need to be a 'j' if day numbers < 10 are single digit.
I need a way to convert this format Tue, 20 Oct 2015 17:43:23 0000
to the datetime format that MySQL accepts.
I have tried to convert it with strtotime() but the function returns a negative number.
The problem appears to be the trailing zeroes, by trimming them from the date string it seems to work fine. The code below uses one of the Date constants - change that for the format desired.
$d='Tue, 20 Oct 2015 17:43:23 0000';
echo date( DATE_COOKIE, strtotime( trim($d,' 0000') ) );
outputs -> Tuesday, 20-Oct-15 17:43:23 BST
echo date( 'Y-m-d H:i:s', strtotime( trim($d,' 0000') ) );
outputs -> 2015-10-20 17:43:23
Try this with your time specified as the $inputtime variable:
strftime("%F %H:%M:%S", strtotime($inputtime))
The problem lies in your time format Tue, 20 Oct 2015 17:43:23 0000. Here 0000 means time zone. But it should have format + or - before value to work properly. Look at example:
echo strtotime("Tue, 20 Oct 2015 17:43:23 +0000");
Try this
$date = \DateTime::createFromFormat('r',your date);
$date = $date->format(format that you need);
I am using strtotime for saving date like strtotime($_POST['end_date']) and this give me format 1441785600 that show very fine in google calendar but when I save string like
Thu Sep 03 2015 14:00:00 (24 hour format)
Data stop displaying in google calendar, I want to convert above sample (24Hours) using strtotime and convert it into something like that 1441785600
You may use something like this which currently doesn't give as you want, but may be useful-
$date = 'Sep 03 2015 14:00:00';
$parsedDate = date_parse_from_format('M d Y H:i:s', $date);
$time_stamp = mktime(
$parsedDate['hour'], $parsedDate['minute'], $parsedDate['second'],
date('n', strtotime($parsedDate['month'])), $parsedDate['day'], $parsedDate['year'],
date('I')
);
You could do:
$dateString = 'Thu Sep 03 2015 14:00:00 (24 hour format)';
echo strtotime(preg_replace('~\w+\s(.+)\s\(.+~','\1',trim($dateString)));