# How to set timezone when use python sdk?

**URL:** https://discuss.elastic.co/t/how-to-set-timezone-when-use-python-sdk/329011
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [March 31, 2023, 6:51am UTC](https://discuss.elastic.co/t/how-to-set-timezone-when-use-python-sdk/329011 "2023-03-31T06:51:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![KeithTt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keithtt/32/29447_2.png) [@KeithTt](https://discuss.elastic.co/u/KeithTt)
#### Post date: [March 31, 2023, 6:51am UTC](https://discuss.elastic.co/t/how-to-set-timezone-when-use-python-sdk/329011/1 "2023-03-31T06:51:27Z")

</div>

```json
{
  "_index": "mysql_backup_stat",
  "_type": "_doc",
  "_id": "addb-m15-2023-03-31T02:31:22.920268+08:00",
  "_version": 1,
  "_score": null,
  "_source": {
    "timestamp": "2023-03-31T02:31:22.920268+08:00",
    "hostname": "m15",
    "dbname": "addb",
    "result": "SUCCESS"
  },
  "fields": {
    "timestamp": [
      "2023-03-30T18:31:22.920Z"
    ]
  },
  "sort": [
    1680201082920
  ]
}

```

The timezone in ES is UTC, how to set it to local time?

Here is my code:

```python
with Elasticsearch(hosts=hosts, timeout=300) as es:
    if not es.indices.exists(index=index_name):
        es.indices.create(index=index_name)

    doc = {
        "timestamp": timestamp,
        "hostname": hostname,
        "dbname": dbname,
        "result": result
    }

    doc_id = "{}-{}-{}".format(dbname, hostname, timestamp)
    es.index(index=index_name, body=doc, id=doc_id)

```

and the sdk doc:  
[https://elasticsearch-py.readthedocs.io/en/v7.14.0/api.html#elasticsearch.Elasticsearch.index](https://elasticsearch-py.readthedocs.io/en/v7.14.0/api.html#elasticsearch.Elasticsearch.index)

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [April 4, 2023, 1:49am UTC](https://discuss.elastic.co/t/how-to-set-timezone-when-use-python-sdk/329011/2 "2023-04-04T01:49:09Z")

</div>

Elasticsearch only stores data in UTC, you cannot change that and all you can do is store the UTC offset in the timestamp.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 2, 2023, 1:49am UTC](https://discuss.elastic.co/t/how-to-set-timezone-when-use-python-sdk/329011/3 "2023-05-02T01:49:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
