Convert any datetime to english datetime
Show older comments
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
More Answers (1)
Peter Perkins
on 5 Jul 2018
Edited: Peter Perkins
on 5 Jul 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.
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!