I am wondering is there any function that would return the current time in seconds, just 2 digits of seconds? I’m using gcc 4.4.2.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following complete program shows you how to access the seconds value:
It outputs:
How it works is as follows.
time()to get the best approximation to the current time (usually number of seconds since the epoch but that’s not actually mandated by the standard).localtime()to convert that to a structure which contains the individual date and time fields, among other things.tm_secin your case but I’ve shown a few of them).Keep in mind you can also use
gmtime()instead oflocaltime()if you want Greenwich time, or UTC for those too young to remember :-).