Effacer les filtres
Effacer les filtres

How to extract date and time that not in datetime format?

2 vues (au cours des 30 derniers jours)
Brandon Leonard
Brandon Leonard le 12 Avr 2018
File name example
20160914_565w081_Laurel_Washingtondc_jb_jr_161451_001.mat
20160914 date 161451 time
The position of the date and time in the file name will be the same for all files. The file name data is a string stored in a cell
I need to create a time series (e.g. ts = timeseries(data,time) creates the time-series object using the specified data and time.) using the date and time from the file name as the ts.TimeInfo.StartDate
How do I extract the date and time from the file name to appear in the format of the the StartDate property.
ts.TimeInfo.StartDate = '10/27/2005 07:05:36';

Réponse acceptée

Walter Roberson
Walter Roberson le 12 Avr 2018
dates = cellfun( @(S) datetime(S([1:8, 44:49]), 'InputFormat', 'yyyyMMddHHmmss', 'Format', 'MM/dd/yyyy HH:mm:ss'), FileNamesCell );

Plus de réponses (0)

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