开发者

create variable to hold time created

Im creating a contact list program and need to beable to record when the contact was created and list the contacts according to their creation date.

what can i use to give a variable a date? i know the time.h file has something inside, but i dont know how to use it with less code as possible.

perhaps

time.h seconds = timeStamp;

?

开发者_高级运维

if this is the way, then what would the output be? and whats the best way to output it in order? this variable will be part of a class.


I know you can use time_t for dates. If you need higher precision, use clock_t

You can get the current time as follows. Note that what is stored is an integer value of the number of seconds since January 1st, 1970.

#include <time.h>
....
time_t s = time(NULL);

See this for further details. Hope that helps!


#include <time.h>
...
time_t seconds = time(NULL);

The seconds variable will contain the number of seconds since 1970, which is enough information to store both date and time.

You can use the asctime function to convert this value into a human-readable string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜