To get the system time


   I need to get the system time in yy/mm/dd hr:min:sec:millisec format. I tried ctime(), but the result is in string format. Then tried localtime(), but result is incorrect date and time. Could you tell the reason why localtime() doesnt show correct time and date. 

Also using localtime() will not give time in milliseconds. Is there any api to get all the details in just one API.

Thanks in advance,

localtime() always works right for me. Is it possible that you don’t have your time zone set up correctly?

If you need the time in milliseconds you may want to look at clock_gettime() … ttime.html

This won’t help your time zone issue but does give better resolution than localtime().

I’m not sure what you’re looking for though if you want the time in “yy/mm/dd hr:min:sec:millisec format” but not as a string? What format do you need it in?

I used localtime() which returns struct tm * and tried to access the individual elements in struct tm. So got incorrect time. Now used strftime and converted time to string format.
Thanks …

If you got the wrong time, your timezone is not set correctly. You have a choice. You can either fix the timezone, or set your backup clock to local instead of GMT.