Getting value of a COM Date object in MATLAB
1 次查看(过去 30 天)
显示 更早的评论
I am working with a library that handles a set of COM objects in MATLAB. One of the COM objects returns a Date object/value. When this is requested in MATLAB, I get it as a string, formatted using the regional settings of the computer.
So, depending on the computer running it (regional settings), the date part may end up as:
yyyy-mm-dd
mm-dd-yyyy
dd-mm-yyyy
m/d/yyyy
d/m/yyyy
and the time part similarly:
HH:MM:SS
hh:MM:SS AM/PM
HH:MM:SS.SSS
hh:MM:SS.SSS AM/PM
Depending on whether the Date object contains a time part, a day part, or both, any variations of above may occur. Bottom line is that I have not been able to make a method, that correctly parses the date to a valid date-time vector in MATLAB
Is there another way to do this, that I have missed, that does not involve parsing a string in a regional format?
If not, it would be nice with some build-in method in MATLAB that can do this conversion (feature request...).
0 个评论
采纳的回答
Friedrich
2013-10-23
编辑:Friedrich
2013-10-23
Hi,
since you are on Windows you can use .NET to get the current System setting:
settings = System.Globalization.DateTimeFormatInfo
After that you can access certain property which tell you how the date and time is formated, e.g.
>> settings.LongDatePattern
ans =
dddd, dd MMMM yyyy
>> settings.LongTimePattern
ans =
HH:mm:ss
>> settings.ShortDatePattern
ans =
MM/dd/yyyy
>> settings.ShortTimePattern
ans =
HH:mm
You can use this information to call the datevec function with the correct format specifier.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Use COM Objects in MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!