Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I must convert to SYSTEMTIME to CString in this format:

monday 4 september 2014, 12:00:34

how must I do?

What I have tried:

I searched on internet but I don't find with this format
Posted
Updated 25-Jan-24 23:20pm

 
Share this answer
 
Comments
CPallini 26-Jan-24 6:36am    
5.
Richard MacCutchan 26-Jan-24 6:39am    
Thanks.
Since the system time is already available in a structure, you can simply output it in a C-String using snprintf(). The minimum length for a 4-digit year should be 38 characters.
C
// SYSTEMTIME lt;
const char* days[] = { "Sunday", ... };
const char* months[] = { .. };
#define MAXOUTPUTLEN 40
char outputString[MAXOUTPUTLEN];
snprintf(outputString, sizeof(outputString), 
     "%s %d %s %d, %02d:%02d:%02d", days[lt.wDayOfWeek], ...

It would also be possible to calculate the length with snprintf in order to reserve an optimally fitting C-string.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900