> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/change-the-time-zone-offset-of-a-datetime-object.md).

# Change The Time Zone Offset Of A DateTime Object

Let's say you have a timestamp string that you parse with [`DateTime.parse`](https://ruby-doc.org/stdlib-2.6.1/libdoc/date/rdoc/DateTime.html#method-c-parse).

```ruby
> DateTime.parse('2021-02-23T11:59:11')
#=> Tue, 23 Feb 2021 11:59:11 +0000
```

Without the specification of a time zone offset in the timestamp string, it will be parsed as UTC.

If you want to change it to another time zone, you can alter the `offset` option of the `DateTime` object. Rails provides the [`#change`](https://api.rubyonrails.org/classes/DateTime.html#method-i-change) method for doing this.

```ruby
> DateTime.parse('2021-02-23T11:59:11').change(offset: '-600')
#=> Tue, 23 Feb 2021 11:59:11 -0600
```

By changing the `offset` to `-600`, the `DateTime` now represents a time in Central Time.

[source](https://stackoverflow.com/a/47861810/535590)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/programmy/rails/change-the-time-zone-offset-of-a-datetime-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
