Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
May 6, 1997

The time.h Header File

Question:
I am trying to write a program that provides a constructor that's capable of using the current time from the time() function declared in the C standard library header to initialize an object of the time class and provide an output of the format H:MM:SS.

Answer:
It's very simple, actually.

time() returns a time_t, which is really the number of seconds elasped since 00:00:00.0 1 January 1970.

The trick is to pass this value to localtime(). This returns a struct tm also defined in time.h, which has all the goodies inside it. Take a look at time.h; also, read the man pages for localtime.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date