How to set timezones for datetimes read from parquet files?
17 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!