필터 지우기
필터 지우기

How to set timezones for datetimes read from parquet files?

조회 수: 15 (최근 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by