PHP: how convert this time string? - php

i would convert this time (strftime?)
2013-07-12T07:59:27+0000
in a more simple to read "12/07/2013" (dd-mm-aaaa) and with +2 (i'm in Italy, so this time must be 09:59, no importance for seconds).
Thank you very much!
PS Could you tell me what "kinda of time expression" is, so next time i'll be more capable to search in Google without ask? :)

Try this:
echo date('d/m/Y H:i', strtotime('2013-07-12T07:59:27+0000'));
For more, read this: http://php.net/manual/en/function.strtotime.php

Related

php function for linux time conversion

I'm new to PHP and I need a PHP function that converts Linux times like 1396310400 from $variable and returns a human-readable date like 1. apr. 2014! (time of day not needed)? Any suggestions is much appreciated.
echo date('d/m/Y', $time_linux);
read here: http://php.net/manual/en/function.date.php to learn how to modify the result to show exactly what you want.
Thanx for your input.
This worked and returned a human readable date into my wpallimport run - at first I just did not understand the syntax:
function overtagelsesdato($time_linux) {
echo date('d/m/Y', $time_linux);
}
thank you OfirH!

Time format conversion

I need to convert a specific date format into local time (Europe/Sarajevo), I have the time in this format 2013-02-17T15:00:00Z which I don't really understand and this is why I don't know how to convert it to the Europe/Sarajevo time, who knows maybe it is already Sarajevo time, I don't know...
OK I can parse it and remove the T and Z and get a time but these letters mean something, probably they affect the result time...
The result time is for example 2013-02-17 18:00:00, probably there will be a difference due to the letters T and Z which are probably time offset.
Use DateTime. It's much better for working with timezones:
$datetime = new DateTime('2013-02-17T15:00:00Z');
$datetime->setTimeZone(new DateTimeZone('Europe/Sarajevo'));
echo $datetime->format('c');
Reference
DateTime
DateTimeZone
See it in action
You can use php date function like this
$date = '2013-02-17T15:00:00Z';
echo date('Y-m-d H:i:s',strtotime($date));
See the Manual

Human readable date into timestamp

I am trying to parse a logfile, using human readable dates without a year into a timestamp. I have looked over the function strtotime() but haven't had any success with it.
Example time: Apr-26-10:49:36
which is the equiv of "M-j-H:i:s" for the date() function.
Edit: without a year, in my case here..its perfectly fine to assume the year is the current year.
I've created a script to break this down in the past, but it was long and redundant. I was hoping for a more simplified way of doing this. Any help, or pointing in the right direction would be greatly appreciated :D
If you know the format of the date, you can use strptime to parse it. This returns an array that you can use to determine the arguments for mktime.
Maybe not the prettiest way to do it but it works
The problem why the strtotime function is not working is because the hyphen between the Day and the Hour 26-10.
You can replace the - and then use strtotime.
echo date('Y-m-d H:i:s', strtotime(str_replace('-', ' ', 'Apr-26-10:49:36')));

How do I get a date in UK local time using PHP?

I'm using the unix timestamp to show when a message was posted in my project but when I came to displaying the exact time of the post I realized it was about 12 hours behind.
I'm in the UK and my server is in the US (might be the problem).
Is there a simple way of converting the unix timestamp into a readable British time?
$timestamp = time();
print date("F jS, Y", strtotime($timestamp));
Any help would be great,
Thanks!
At the top of your script, write:
date_default_timezone_set('Europe/London');
Or if your PHP is >= 5.2.0:
date_timezone_set('Europe/London');
Just call date_timezone_set with the appropriate parameter for the UK at the start of your script when displaying the dates (not when recording them; I 'm not sure, but it might result in the "wrong" timestamps being recorded).
Edit: The timezone you want is 'Europe/London'.
try date-default-timezone-set.
date_default_timezone_set('Europe/London');
Use date_default_timezone_set('Europe/London'); to set the time zone to London's time. Not sure if it works with summer/winter time.
the simplies way is to substruct gmt offset. e.g:
echo(date('Y-m-d h:i'), $myvalue - 60 * 60 * $nhours));
where $nhours - time defference in hours.
This one worked for me
date_default_timezone_set('Europe/London');

Could anyone pls convert this unixtime stamp in php?

I am struggling with this unixtimestamp and just cant find a correct format
Here is the stamp:
1295058844
And here is the result i want to achive:
01/14/2011 at 21:34 EST
And here is my almost correct but no luck code:
$start_unixtime = '1295058844';
date('m/d/Y \a\t H:i', intval($start_unixtime));
Basically i want EST time format, hope someone could help and sorry for such stupid question.
Thank you.
You need to use the date_default_timezone_set function before you call date.
date_default_timezone_set("America/New_York");
List of possible choices.
http://us2.php.net/manual/en/timezones.php
No need for intval.
date_default_timezone_set("TIMEZONENAME");
$start_unixtime = '1295058844';
echo date('m/d/Y \a\t H:i', $start_unixtime);
Maybe to get your "at" into there: date('m/d/Y',$x).' at '.date('H:i',$x)
After that I never could remember the codes, I tend to look them up every time.

Categories