Forum: Ruby Help converting DateTime from UTC

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Geary E. (Guest)
on 2005-12-04 02:03
I trying to convert a parsed time of "2005-12-01T18:00:00Z" to the local
equivalent.

I'm current in -800 (PST) and so and doing the following:
 DateTime.parse("2005-12-01T18:00:00Z").new_offset(-8.0/24)

What I get is very close, but not what I would expect:
 2005-12-01T09:59:59-0800

How do I get this to show 10:00:00? I don't really care about the
seconds, so if there is no easy solution, I'll have to write a method to
round to the nearest minute.

Thanks,
Geary
khaines (Guest)
on 2005-12-04 02:46
(Received via mailing list)
On Saturday 03 December 2005 5:03 pm, Geary Eppley wrote:
> I trying to convert a parsed time of "2005-12-01T18:00:00Z" to the local
> equivalent.
>
> I'm current in -800 (PST) and so and doing the following:
>  DateTime.parse("2005-12-01T18:00:00Z").new_offset(-8.0/24)
>
> What I get is very close, but not what I would expect:
>  2005-12-01T09:59:59-0800

DateTime.parse("2005-12-01T18:00:00Z").new_offset(Rational(-8,24))


Kirk H.
phasis68 (Guest)
on 2005-12-04 02:46
(Received via mailing list)
Hi,
----- Original Message -----
From: "Geary Eppley" <removed_email_address@domain.invalid>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <removed_email_address@domain.invalid>
Sent: Sunday, December 04, 2005 9:03 AM
Subject: Help converting DateTime from UTC


> seconds, so if there is no easy solution, I'll have to write a method to
> round to the nearest minute.
>

Try
DateTime.parse("2005-12-01T18:00:00Z").new_offset(Rational(-8,24))

HTH,

Park H.
Geary E. (Guest)
on 2005-12-04 04:13
thanks. That did it.
This topic is locked and can not be replied to.