time returns an integral type which has the number of seconds since an epoch.
localtime decodes a time integral type into a record (struct tm) that breaks out the date/time components for easy access. localtime fills in a static instance of struct tm within the runtime library (actually, there's one per thread) and returns it's address. You simply use it without having to check for NULL or releasing it.
one more: when all this happens at runtime library why do we have two different methods one for getting the total seconds elapsed from pre-defined datetime, then again one for putting in struct format ...instead just one method call and we have *tm??
and also with the fact that there is no need to have user defined/ different struct tm format.. i think thts not even allowed to avoid clash with what already defined in library.....
or am i going deep into something unnecessary ..??
curiosity is embedded in homosapiens !!!
localtime doesn't return the current time. It returns a record breaking the fields of the time_t passed in; which can be any time, not just the current time.
time() always returns the current time.
localtime has a corresponding function gmtime which returns the Universal Time translation (used to be called Greenwich Mean Time).
There's a family of time functions. It's worth taking a look at all of them.