1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| AnsiString ISODate(TDateTime value) {
// Split date/time object into its parts
unsigned short year,month,day,hours,minutes,seconds,msecs;
value.DecodeDate(&year,&month,&day);
value.DecodeTime(&hours,&minutes,&seconds,&msecs);
// Convert into a string
// Format is "YYYYMMDDTHHMMSSMMM";
AnsiString result;
result=FormatString(20,"%04d%02d%02dT%02d%02d%02d%03d",
year,month,day,hours,minutes,seconds,msecs);
return result;
}
AnsiString FormatString(int bufferSize,const char* format,...) {
// Extract paramters
va_list argList; va_start(argList,format);
// Create buffer
const size_t maxSize=maxSize*sizeof(TCHAR);
char *buffer=new char[maxSize];
try {
// The result of the call to the API
HRESULT apiResult;
// Format the string
apiResult=StringCbVPrintfEx(
buffer, // LPTSTR pszDest,
maxSize, // size_t cbDest,
NULL, // LPTSTR *ppszDestEnd,
NULL, // size_t *pcbRemaining,
STRSAFE_IGNORE_NULLS|STRSAFE_NULL_ON_FAILURE, // DWORD dwFlags,
format, // LPCTSTR pszFormat,
argList // va_list argList
);
// Check if error
if (FAILED(apiResult)) {
// An error occurs while formating the string
buffer[0]='\0';
}
} catch(...) {};
// Delete the list of arguments
va_end(argList);
// Convert buffer into AnsiString
AnsiString result=buffer;
delete[] buffer;
return result;
} |