フィルターのクリア

How to set timezones for datetimes read from parquet files?

8 ビュー (過去 30 日間)
samuels
samuels 2020 年 12 月 23 日
回答済み: Vatsal 2024 年 6 月 13 日
I just started playing around with parquet files for storing large tables of test data. All my data has timestamp columns which when saved has a timezone associated with it. When using parquetread(file) to get the whole table the datetimes are read in and display UTC timestamps for the display format with an empty timezone field. Currently I'm using the following to convert back to my local timezone for display purposes:
data = parquetread(file);
data.Timestamp.TimeZone = 'UTC';
data.Timestamp.TimeZone = 'local';
Is there a more concise way to do this?

回答 (1 件)

Vatsal
Vatsal 2024 年 6 月 13 日
Hi,
The more concise approach would be to directly convert the datetime objects to the local timezone without explicitly setting it to 'UTC' first. This can be achieved by utilizing the 'TimeZone' parameter within the 'datetime' function to convert the timestamps directly to the preferred timezone.
Here is an example:
data = parquetread(file);
data.Timestamp = datetime(data.Timestamp, 'TimeZone', 'UTC');
data.Timestamp.TimeZone = 'local';
In this code, the 'datetime' function is used to convert the timestamps to the 'UTC' timezone. Then, the 'TimeZone' property of the datetime object is set to 'local' to convert it to your local timezone.
I hope this helps!

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by