Effacer les filtres
Effacer les filtres

How to set timezones for datetimes read from parquet files?

15 vues (au cours des 30 derniers jours)
samuels
samuels le 23 Déc 2020
Réponse apportée : Vatsal le 13 Juin 2024
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?

Réponses (1)

Vatsal
Vatsal le 13 Juin 2024
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!

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by