Getting value of a COM Date object in MATLAB
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jesper
el 23 de Oct. de 2013
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 comentarios
Respuesta aceptada
Friedrich
el 23 de Oct. de 2013
Editada: Friedrich
el 23 de Oct. de 2013
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.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!