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".

 Accepted Answer

Rik
Rik on 3 Jul 2018
Edited: Rik on 3 Jul 2018
How about this?
date=datetime(file.datenum,'ConvertFrom','datenum');

2 Comments

Yes this is correct. Thank you!
Works for me too. Thanks

Sign in to comment.

More Answers (1)

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.

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!