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!