PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Date string manipulation
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Date string manipulation

Réponse
 
LinkBack Outils de la discussion
Vieux 27/03/2008, 10h19   #1
GorseFox
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Date string manipulation

Forgive me. I am new to PHP and am a little confused by date
manipulation and would appreciate some guidance.
I have a string containing a date which has been parsed from and RSS
feed. This looks something like: "Tue, 25 Mar 2008 04:28:18 -0500" and
is stored in $rssdate

I would like to manipulate this date to correct the timezone
adjustment. (I happen to know that the item I am referencing was
actually timestamped at 09:28:18). I suspect that I have to turn it
into a timestamp (is that correct?)

Attempts to use strtotime($rssdate) have failed... and dropping the
-0500 allows strtotime to complete, but it returns a date of 18 Mar
(which is counter-intuitive, to say the least).

Can anyone offer me any clues?
  Réponse avec citation
Vieux 27/03/2008, 10h33   #2
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date string manipulation

GorseFox schreef:
> Forgive me. I am new to PHP and am a little confused by date
> manipulation and would appreciate some guidance.
> I have a string containing a date which has been parsed from and RSS
> feed. This looks something like: "Tue, 25 Mar 2008 04:28:18 -0500" and
> is stored in $rssdate
>
> I would like to manipulate this date to correct the timezone
> adjustment. (I happen to know that the item I am referencing was
> actually timestamped at 09:28:18). I suspect that I have to turn it
> into a timestamp (is that correct?)
>
> Attempts to use strtotime($rssdate) have failed... and dropping the
> -0500 allows strtotime to complete, but it returns a date of 18 Mar
> (which is counter-intuitive, to say the least).
>
> Can anyone offer me any clues?


i think you need strtotime:
http://nl3.php.net/manual/en/function.strtotime.php

and strftime:
http://nl3.php.net/manual/en/function.strftime.php

--
Luuk
  Réponse avec citation
Vieux 27/03/2008, 11h25   #3
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date string manipulation

GorseFox wrote:

> Attempts to use strtotime($rssdate) have failed...


What version of PHP are you using. Parsing the example date you provided
with strtotime seems to work fine here with PHP 5.2.5.


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 21:39.]

Best... News... Story... Ever!
http://tobyinkster.co.uk/blog/2008/03/23/hypnotist/
  Réponse avec citation
Vieux 27/03/2008, 17h25   #4
GorseFox
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date string manipulation

On Mar 27, 10:25 am, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
> GorseFox wrote:
> > Attempts to use strtotime($rssdate) have failed...

>
> What version of PHP are you using. Parsing the example date you provided
> with strtotime seems to work fine here with PHP 5.2.5.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
> [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 21:39.]
>
> Best... News... Story... Ever!
> http://tobyinkster.co.uk/blog/2008/03/23/hypnotist/


Toby, I'm using PHP 5.2.5

I have no idea what the problem was, but I have managed to circumvent
the problem. I have no doubt that there is a better way, but this is
the approach I used:

// Now the publication date needs adjusting because the feedburner
provides it with a 5 hour offset
$rss_date_array = explode(" ",$item_published_date); // Get the
components of the date
$tmp[0] = $rss_date_array[1]; // Day
$tmp[1] = $rss_date_array[2]; // Month
$tmp[2] = $rss_date_array[3]; // Year
$tmp[3] = $rss_date_array[4]; // Time of day
$tmpstr = implode(" ",$tmp); // Recreate a string
$offset = substr($rss_date_array[5],1,2); // Grab the hour offset
from UTC
$rss_timefmt = strtotime($tmpstr); // Converts the date from the
feed to a timestamp
$rss_adjusted = $rss_timefmt + ($offset * 60 * 60); // and adjust by
the requisite number of seconds
  Réponse avec citation
Vieux 28/03/2008, 10h28   #5
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date string manipulation

GorseFox wrote:

> $offset = substr($rss_date_array[5],1,2); // Grab the hour offset from UTC


Why ignore the minutes? Yes, there do exist timezones where the minutes
are not '00'.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 20:47.]

Best... News... Story... Ever!
http://tobyinkster.co.uk/blog/2008/03/23/hypnotist/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11261 seconds with 13 queries