Creating TimeStamp
-
Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following:
char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
-
Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following:
char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
Hi, For the year, you need to add 1900 (see MSDN for more information). So, your
sprintf
turn to:sprintf(dateString,"**%4d%02d%02d**",newtime->tm_year **+ 1900** , newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"**%02d%02d%02d**",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
The bold letters are those places where I made changes. Hope that helps. Kiran. -
Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following:
char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
-
Programm3r wrote:
format: yyyymmddhhmmss
Use:
_tcsftime
(dateString, 20, _T("%Y%m%d%H%M%S"), newtime);
Thank you very much for the help. Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
-
Hi, For the year, you need to add 1900 (see MSDN for more information). So, your
sprintf
turn to:sprintf(dateString,"**%4d%02d%02d**",newtime->tm_year **+ 1900** , newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"**%02d%02d%02d**",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
The bold letters are those places where I made changes. Hope that helps. Kiran.Thanks kvrnkiran for the help :) Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
-
Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following:
char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
Programm3r wrote:
...I'm experiencing some problems.
One of which seems to be not explaining the problem.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Programm3r wrote:
...I'm experiencing some problems.
One of which seems to be not explaining the problem.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
DavidCrow wrote:
One of which seems to be not explaining the problem.
Strange that the other two people understood the question :eek: ....
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^