DateTime about the zone

U

Une Bévue

i'm reading a news server from ruby asking for DATE, it returns :
"20100612" for the date, that's ok for today
and :
"073429" for the time when it is 2 hours more

i want to return a correct datetime, taking into account the zone
5paris/france) i think it is + 2 H ?

but using datetime and the following :

text = ["20100612", "073429"] # returned by the server thru Net::NNTP

i translate to =
datetime_str =
text[0].gsub(/(\d\d\d\d)(\d\d)(\d\d)/,'\1-\2-\3')+'T'+text[1].gsub(/(\d\
d)(\d\d)(\d\d)/,'\1:\2:\3')+'-02:00'

giving :

datetime_str = '2010-06-12T07:34:29+02:00'

if i read back the hour by :

datetime = DateTime.parse('2010-06-12T07:34:29+02:00')

time = adatetime.strftime(fmt='%H%M%S')

i get always :
073429
regardless of the time decay i put by the end of string (ie '+02:00' or
'-02:00' or 'CEST'

clearly i don't understand...
 
B

Brian Candler

Une said:
datetime = DateTime.parse('2010-06-12T07:34:29+02:00')

time = adatetime.strftime(fmt='%H%M%S')

i get always :
073429
regardless of the time decay i put by the end of string (ie '+02:00' or
'-02:00' or 'CEST'

clearly i don't understand...
=> "073429 -0200"
 
B

Brian Candler

Une said:
i'm reading a news server from ruby asking for DATE, it returns :
"20100612" for the date, that's ok for today
and :
"073429" for the time when it is 2 hours more

You mean it's 093429 local time in France?

That means that 073429 is UTC.
=> #<DateTime: 212143088069/86400,0,2299161>

I don't know how to ask a DateTime to change to the local timezone, but
I can do it with Time:
=> Sat Jun 12 08:34:29 +0100 2010
 
U

Une Bévue

Brian Candler said:
You mean it's 093429 local time in France?

yes, it was )))

in France it's UTC + 2 hours now.
That means that 073429 is UTC.

=> #<DateTime: 212143088069/86400,0,2299161>

I don't know how to ask a DateTime to change to the local timezone, but
I can do it with Time:

=> Sat Jun 12 08:34:29 +0100 2010

Thanks, fine, seems to be easier to do with Time than with DateTime
(strange enough!)

even i've corrected datetime with tzinfo, gave the correct hour with a
false time zone, strange...

here the datas :
utc_datetime_str = '2010-06-12T07:34:29UTC'
tz = TZInfo::Timezone.get('Europe/Paris')
local = tz.utc_to_local(utc_datetime)
# --> local = 2010-06-12T09:34:29+00:00

here the hour is correct BUT the time zone :
local_zone = local.strftime(fmt='%z')
# --> local_zone = local.strftime(fmt='%z') = +0000

I'll switch to Time )))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top