Karol Selak
Karol Selak

Reputation: 4774

How to change timezone by integer value?

My current Time object looks like that:

2015-01-10 17:13:00.000000000 +0000

While I need it to look like that:

2015-01-10 18:13:00.000000000 +0100

I'd like to just set a value of timezone offset to receive that, without knowing names of timezones in strings, somethig like:

my_date.set_timezone_offset(1)

How could I do that?

Upvotes: 0

Views: 1820

Answers (2)

John Baker
John Baker

Reputation: 2398

So to change the Time depending by the given offset, you have to use new_offset method which is part of DateTime (not sure if this works this Time objects, if not you can try to parse it):

time = "2015-01-10 17:13:00.000000000 +0000".to_datetime
Then use the method:

time.new_offset("+10:00")

This will return DateTime with provided offset also changed time according to that offset.

Upvotes: 2

Igor Drozdov
Igor Drozdov

Reputation: 15045

DateTime.now.change(offset: "+0100")

Returns datetime with provided offset

Upvotes: 1

Related Questions