Anyone know what the ULong "timestamp" returned from mdlFile_getTimeStamp represents or how to convert it to a string? I initially thought it was a time_t similar to what time() returns and tried to use localtime() to convert it but no luck. The docs for this function dont help either.
Please try the following snippet:
struct tm tm1;char myStr[64];UInt32 dateTime = mdlFile_getTimeStamp (yourFileName);tm1 = *localtime ((time_t *)&dateTime);sprintf (myStr, "%4d-%02d-%02d %02d:%02d:%02d", tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm1.tm_sec);HTH, YongAn
struct tm tm1;char myStr[64];UInt32 dateTime = mdlFile_getTimeStamp (yourFileName);
tm1 = *localtime ((time_t *)&dateTime);sprintf (myStr, "%4d-%02d-%02d %02d:%02d:%02d", tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
Works perfect! Thanks YongAn.
Yongan.Fu said:struct tm tm1;char myStr[64];UInt32 dateTime = mdlFile_getTimeStamp (yourFileName);tm1 = *localtime ((time_t *)&dateTime);sprintf (myStr, "%4d-%02d-%02d %02d:%02d:%02d", tm1.tm_year+1900, tm1.tm_mon+1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
Good job Yongan, thanks.
When I tried this code using MicroStation vi SS3 SDK, it launched an exception.
Inside time.h, there is a note as follows;
// starting with MicroStation 08.11, we use 64-bit time_t.typedef __int64 time_t;
So I updated your code as follows and it works fine;
struct tm tm1; time_t dateTime = (time_t)mdlFile_getTimeStamp(ms_consolelog); tm1 = *localtime(&dateTime); sprintf(consolelogTimestamp, "%4d-%02d-%02d %02d.%02d.%02d", tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
Kind regards,
Sedat AlisAEC Technology Inc.
Thanks for your update.
Sedat Alis said: I updated your code
I you want to move onwards from C-style file times, then consider the C++ library additions in recent years.
C++ includes support for two types of time manipulation:
The C++ std:: Filesystem library, which provides a 21st century API. If you don't have C++ 17 then you can use Boost::FileSystem. This article describes a C++ File Collector. The source code is freely available.
Regards, Jon Summers LA Solutions