Converting UTC time to general date/time

Converting UTC time to general date/time

Post by SlJvemF » Mon, 18 Oct 2004 23:37:03


I have a filename that has a UTC time in it. (e.g.
78286.data.20041017T103105,750Z.DAT) in a CString

Once I extract the time stamp is there a function that will convert
20041017T103105 to "10/17/2004 10:31:05". Thanks.
 
 
 

Converting UTC time to general date/time

Post by Norman Bul » Tue, 19 Oct 2004 09:25:23


If you're sure that the string always looks exactly like the above, this
ought to do it.

/* Parses a string of the form
*.*.yyyymmddThhmmss,*.* (where * represents any string of
characters)
and constructs a string of the form
mm/dd/yyyy hh:mm:ss
The input string is supplied by strIn and the output string stored in
strOut. strOut must be at least 20 charactrs long.
Note: strIn is modified by this procedure.
*/
void GetTimestamp(char strIn[], char strOut[])
{ char strDay[4], strMonth[4], strYear[6];
char strHour[4], strMinute[4], strSecond[3];
char *p;

p = strchr(strIn, ',');
*p = '\0';
strcpy(strSeconds, p -= 2);
*p = '\0';
strcat(strcpy(strMinute, p -= 2), ":");
*p = '\0';
strcat(strcpy(strHour, p -= 2), ":");
*--p = '\0';
strcat(strcpy(strDay, p -=2 ), " ");
*p = '\0';
strcat(strcpy(strMonth, p -= 2), "/");
*p = '\0';
strcat(strcpy(strYear, p -= 4), "/");
strcat(strcat(strcpy(strOut, strYear), strMonth), strDay);
strcat(strcat(strcat(strOut, strHour), strMinute), strSecond);
}

Norm
--