convert datestring to datenum problem.

5 vues (au cours des 30 derniers jours)
davit petraasya
davit petraasya le 30 Nov 2016
Hi
Does anybody know how to convert this date to number:
My date is 2016-11-22T13:12:47.320Z Now I am trying to convert it to number.
op_datetime = '2016-11-22T13:12:47.320Z';
format = 'yyyy-mm-ddTHH:MM:SS.FFFZ';
datenum(op_datetime, format)
I tryed like this above, but it is giving error.
Thanks!
  2 commentaires
Jan
Jan le 30 Nov 2016
Modifié(e) : Jan le 30 Nov 2016
Please post the error message.
davit petraasya
davit petraasya le 30 Nov 2016
DATENUM failed.
Error in ==> andijan at 19
date_num=datenum(op_datetime, format)
Caused by: Error using ==> dtstr2dtnummx
Failed on converting date string to date number.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 30 Nov 2016
Modifié(e) : Jan le 30 Nov 2016
The trailing 'Z' is not recognized.
op_datetime = '2016-11-22T13:12:47.320Z';
format = 'yyyy-mm-ddTHH:MM:SS.FFF'; % No trailing 'Z'
datenum(op_datetime, format)
  1 commentaire
davit petraasya
davit petraasya le 30 Nov 2016
Thanks Simon, it works!

Connectez-vous pour commenter.

Plus de réponses (1)

Peter Perkins
Peter Perkins le 1 Déc 2016
In R2014b or later, you should consider using datetimes, not datenums:
>> s = '2016-11-22T13:12:47.320Z'
s =
'2016-11-22T13:12:47.320Z'
>> d = datetime(s,'Format','yyyy-MM-dd''T''HH:mm:ss.SSS''Z''')
d =
2016-11-22T13:12:47.320Z
You might want to create the datetimes with the time zone set to UTC, and people working with timestamps that look like that often care about leap seconds:
>> d = datetime(s,'Format','yyyy-MM-dd''T''HH:mm:ss.SSSX','TimeZone','UTC')
d =
2016-11-22T13:12:47.320Z
>> d = datetime(s,'TimeZone','UTCLeapSeconds')
d =
2016-11-22T13:12:47.320Z

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by