Convert any datetime to english datetime

Hi!
I need to check when a file was last time changed to mayby update it. The problem is that these dates gotten by 'dir()' are in Finnish. I've tried the following:
file = dir(path);
date = file.date; % '03-heinä-2018 10:18:05'
englishDate = datetime(date, 'Locale', 'fi_FI');
englishDateTry2 = datetime(date, 'Locale', 'system');
But this returns
"Could not recognize the date/time format of
'03-heinä-2018 10:18:05' using the locale 'fi_FI'. You can specify a format character vector using the
'InputFormat' parameter."
and for the 'system'
Could not recognize the date/time format of '03-heinä-2018 10:18:05' using the locale 'fi_FI'. You can specify a format character vector using the
'InputFormat' parameter.
I'd like the user to be able to use computer on whatever language he/she pleases. Is there a way to archieve this using matlab? The matlab always returns it's datetimes in English, Ie. "03-Jul-2018 11:46:57".

 Réponse acceptée

Rik
Rik le 3 Juil 2018
Modifié(e) : Rik le 3 Juil 2018
How about this?
date=datetime(file.datenum,'ConvertFrom','datenum');

2 commentaires

Otso Brummer
Otso Brummer le 3 Juil 2018
Yes this is correct. Thank you!
Guillaume Baptist
Guillaume Baptist le 3 Août 2022
Works for me too. Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Peter Perkins
Peter Perkins le 5 Juil 2018
Modifié(e) : Peter Perkins le 5 Juil 2018
Here's what was happening (and keep in mind, "sauna" might be the only Finnish word I know):
dir uses system utilities. It appears that Windows (?) wants to abbreviate July as heinä, while the L10n library that datetime uses expects to see heinäk.
>> englishDate = datetime('03-heinäk-2016 10:18:05', 'Locale', 'fi_FI')
englishDate =
datetime
03-Jul-2016 10:18:05
This also crops up with (IIRC) March in German. As Rik suggested, best bet for avoiding language issues when reading file dates from the output of dir is to use the datenum field.

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by