Effacer les filtres
Effacer les filtres

Timestamp in table not recognized as time value

4 vues (au cours des 30 derniers jours)
Malik
Malik le 31 Jan 2022
Commenté : Star Strider le 17 Fév 2023
Hello,
I have the following data time format in a table
'2020-08-03T20:40:00.000Z'
When I try to plot this data with another variable. I get the following message:
Error using scatter (line 54)
Input arguments must be numeric, datetime, duration or categorical.
I am aware that one can remove the T and the Z, in the following manner:
wtg_ref.Timestamp = strrep(wtg_ref.Timestamp, 'T', ' ');
wtg_ref.Timestamp = strrep(wtg_ref.Timestamp, 'Z', '');
However, that does and would not help either. It seems the value in the cell is not treated as time. A clue might be that the time value has quotation marks around it in the cells...
It would, of course be easier, to keep the T and Z in the format.
Support would be very much appreciated. Thank you.
  1 commentaire
Malik
Malik le 31 Jan 2022
I should mention, I also tried: time = datenum('2020-08-01T04:26:18.887Z','yyyy-mm-ddTHH:MM:SS.FFFZ');
But then I lose the milliseconds when I datestr(result)

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 31 Jan 2022
It likel;y needs to be converted to a datetime array —
timestamp = '2020-08-03T20:40:00.000Z'
timestamp = '2020-08-03T20:40:00.000Z'
datetimestamp = datetime(timestamp, 'InputFormat','yyyy-MM-dd''T''HH:mm:ss.SSS''Z''', 'TimeZone','UTC')
datetimestamp = datetime
03-Aug-2020 20:40:00
The desired 'Format' and time zone in the code can be whatever you want.
datetimestamp.Format = 'yyyy-MMM-dd HH:mm:ss.SSS'
datetimestamp = datetime
2020-Aug-03 20:40:00.000
datetimestamp.TimeZone = 'UTC-7'
datetimestamp = datetime
2020-Aug-03 13:40:00.000
The actual format of the month and day are a bit ambiguous, so change those if they are not as I defined them in 'InputFormat'.
.
  6 commentaires
Xiaoqi Davey
Xiaoqi Davey le 17 Fév 2023
Star Strider is the man!
Star Strider
Star Strider le 17 Fév 2023
@Xiaoqi Davey — Thank you!!
A Vote would be appreciated!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by