I want to convert a date as below using php.
Mon Jun 17 2013 14:00:00 GMT 0300 (EEST)
When I run date("Y-m-d H:i:s",strtotime("Mon Jun 17 2013 14:00:00 GMT 0300 (EEST)")) the engine just generates 0300-06-17 15:56:56. If I update the code like date("Y-m-d H:i:s",strtotime("Mon Jun 17 2013 14:00:00 GMT")) it generates 2013-06-17 17:00:00. I have tried again and again but could not solve this issue. How Can I convert dates like this?
try to set the time zone and try
http://php.net/manual/en/function.date.php
Make sure you set your timezone like date_default_timezone_set('America/Los_Angeles') and try using gmdate().
http://us1.php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/function.gmdate.php
If you are trying to convert GMT to your timezone then you should convert both to a UNIX timestamp and do the math.
See:
http://us3.php.net/manual/en/function.date-timestamp-get.php
Please see the solution i posted over here. You can do the similar way to convert GMT to your desired timezone.
converting datetime to gmt
Related
Is PHP's native date() function return Time according to DST?
Let's consider example here. Timezone set in php.ini is America/New_York.If we consider Tue, 20 Dec 2011 20:57:45 +0000 then is it display date Tue, 20 Dec 2011 15:57:45 -0500 or -0400 for DST?
If your timezone is correctly set (see: http://php.net/manual/en/function.date-default-timezone-set.php) then it will account for DST.
Example:
print strtotime('Sat, 03 Nov 2012 20:17:12 0000');
prints nothing :(
And the date string appears to be correct..
it's:
day name, day month name year hour:min:sec timezone
Valid formats are explained in Date and Time Formats.
Consider using DateTime objects, and the createFromFormat() method
I get it you want to add a timezone correction. But the timezone requires a sign.
print strtotime('Sat, 03 Nov 2012 20:17:12 +0000');
This will work
print strtotime('03 Nov 2012 20:17:12');
Output: 1351988232
This works perfectly. You should remove the 0000 and the day (Sat)
I have this strings like this: Thu, 27 May 2010 07:00:00 GMT
I want to convert them to UNIX timestamp
Is there any way?
echo strtotime('Thu, 27 May 2010 07:00:00 GMT');
http://php.net/manual/en/function.strtotime.php
Yes, there is a way! In fact, there is more than one way to do it! ;)
You can use strtotime();
$time_en = "Thu, 27 May 2010 07:00:00 GMT"
$time = strtotime($time_en);
http://fr2.php.net/manual/fr/function.strtotime.php
Need help in date conversion:
Existing date format:
Wed, 01 Dec 2010 00:00:00 -0500
(Day, DD MMM YYYY HH:MM:SS GMT-0500)
To be changed to:
2010-11-29T04:59:59-05:00
(YYYY-MM-DD(T)HH:MM:SS GMT-05:00)
How to handle in PHP?
is there any function available in php for this.
please help
strtotime() (man page) & date() (man page) or DateTime class (man page) should be able to handle this.
echo date('Y-m-d\TH:i:sZ', strtotime('Wed, 01 Dec 2010 00:00:00 -0500'));
echo date('c', strtotime('Wed, 01 Dec 2010 00:00:00 -0500')); // as mentioned by Anthony
or
echo DateTime('Wed, 01 Dec 2010 00:00:00 -0500')->format('Y-m-d\TH:i:sZ');
echo DateTime('Wed, 01 Dec 2010 00:00:00 -0500')->format('c'); // as mentioned by Anthony
First you want the date string in epoch format, so that you can use the date function. My favorite method to do this is the strtotime function:
$epoch_date = strtotime($original_date_string);
Now, you can use the date function to output it however you like. In your case, I believe you are looking for ISO 8601, which is built into the function:
$new_date_string = date('c', $epoch_date);
echo $new_date_string;
date('Y\-m\-d\Th:i:s \G\M\TP');
This will return:
2010-11-26T02:49:24 GMT-05:00
Use the date() formating its much simpler!
You can read all about it right here http://php.net/manual/en/function.date.php
I am parsing a xml, and I get the created time as: Wed, 24 Nov 2010 13:10:00 EST
My requirement is to convert this time into the specified time format using DateTime function before inserting it in the database.
Can anyone help me with this.
Thanks you
Zeeshan
set EST timezone
date_default_timezone_set('America/New_York');
convert to epoch
$epoch = strtotime('Wed, 24 Nov 2010 13:10:00 EST');
get date/time
echo date('Y-m-d H:i:s', $epoch);