How to set timezones for datetimes read from parquet files?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Vatsal
el 13 de Jun. de 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!
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!