kagami01
asked on
How to get in C++ this time format HH.MM.SS?
Hello Experts,
how can i get this time format?
for ex. 17.22.34
i need a string as result
how can i get this time format?
for ex. 17.22.34
i need a string as result
#include <sys/types.h>
#include <sys/timeb.h>
struct tm *current_time;
current_time = localtime(time());
char timebuf[20] = { 0 } ;
strftime(timebuf, 20, "%H.%M.%S", current_time);
#include <sys/timeb.h>
struct tm *current_time;
current_time = localtime(time());
char timebuf[20] = { 0 } ;
strftime(timebuf, 20, "%H.%M.%S", current_time);
ASKER
i can use even the results of strftime even with asctime??
>> i can use even the results of strftime even with asctime??
asctime is another (fixed) way of formatting a time into a string. strftime allows you to choose the format, so you'll need strftime as I showed.
asctime is another (fixed) way of formatting a time into a string. strftime allows you to choose the format, so you'll need strftime as I showed.
ASKER
so how to convert the output of strftime in a string??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or if you mean you want it as an std::string, you can always create one from the timestamp buffer :
time_t now = time(0);
char timestamp_buf[10] = "";
strftime (timestamp_buf, 10,"%H.%M.%S", localtime(&now));
std::string timestamp = std::string(timestamp_buf);
std::cout << timestamp << std::endl;
http://www.cplusplus.com/reference/clibrary/ctime/strftime.html
Open in new window