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

 採用された回答

Rik
Rik 2018 年 7 月 3 日
編集済み: Rik 2018 年 7 月 3 日

3 投票

How about this?
date=datetime(file.datenum,'ConvertFrom','datenum');

2 件のコメント

Otso Brummer
Otso Brummer 2018 年 7 月 3 日
Yes this is correct. Thank you!
Guillaume Baptist
Guillaume Baptist 2022 年 8 月 3 日
Works for me too. Thanks

サインインしてコメントする。

その他の回答 (1 件)

Peter Perkins
Peter Perkins 2018 年 7 月 5 日
編集済み: Peter Perkins 2018 年 7 月 5 日

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.

カテゴリ

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by