Hi,
Can anyone tell me the function in C that converts unix long time (ex: 1020830400) to get hour, min, sec. Any help would be appreciated.
Thanks
Hi,
Can anyone tell me the function in C that converts unix long time (ex: 1020830400) to get hour, min, sec. Any help would be appreciated.
Thanks
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
there is some unix source code out there that displays the time in this format
hrs:minutes:moth:day:year
now (5:47 PM) it would be displayed as
174705082002
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
-PreludeCode:#include <stdio.h> #include <time.h> int main ( void ) { struct tm *t; time_t now; now = time ( NULL ); t = localtime ( &now ); printf ( "%d:%d:%d\n", t->tm_hour, t->tm_min, t->tm_sec ); return 0; }
My best code is written with the delete key.
> hmm
Ok, I'm sorry. What's the point of these posts?
The world is waiting. I must leave you now.
some strange infatuation methinks !!
anyway...
time.h function is "giving the time as set in the systems internal clock, seconds since jan 1st 1970". so i take it this is always the correct time ?? not the same as the time youve set on your pc obviously.
what about daylight saving times, times in different parts of the world etc. ??? its all programmed into the 'time chip' is it ??
ie mines in GMT. and will it automatically add and subtract an hour like the pc clock ?
just wondering......
Steve
I'm pretty sure all these functions use the time you've set on your pc. Somewhere there's a menu to change the time zone. It's either in your Clock's menu, or I think on older systems its under:Originally posted by stevey
time.h function is "giving the time as set in the systems internal clock, seconds since jan 1st 1970". so i take it this is always the correct time ?? not the same as the time youve set on your pc obviously.
Start -> Settings -> Control Panel -> Regional Settings
I'm guessing the pc clock is always GMT, it simply displays the time based on your time zone.
Two time functions in C are localtime() and gmtime(), which convert the "seconds since jan 1st 1970" to either local time or GMT.
Last edited by swoopy; 05-09-2002 at 04:25 PM.
> I'm pretty sure all these functions use the time you've set on your pc.
Doesn't it have something to do with your system's BIOS?
The world is waiting. I must leave you now.
>Doesn't it have something to do with your system's BIOS?
Ok, where's all the PC hardware experts out there? Help us out.
I would think this "seconds since jan 1st 1970" is stored in some nonvolatile memory, like EEPROM, unless they use a battery to keep the clock running.
having run Preludes code....
the time is obviously simply the time which is set on your pc, its not the correct time at all. just as near as can be expected, i mean its not a ceasium clock !! what was i thinking !!! i'm so dumb !! the time is kept on a chip, refreshed with your battery, but nothing but caesium clocks can keep correct time.
it is counting the seconds, but will be incorrect, all clocks need correcting from time to time.......and it auto changes daylight saving time etc and you adjust your own zone from GMT.
surprised windows doesn't have a time adjuster so when you go online it ensures your clock is correct, like those fancy wrist watches taking a radio signal.........
Last edited by stevey; 05-09-2002 at 07:11 PM.
Steve
Well, on my old 486 that I no longer have due to disassembling () the battery died. My brother, I believe, in the last few moments of that computers life replaced it with something much similar to a battery for a watch or something...I-dunno I just laughed at the situation. Anyhow, before hand when the battery was dying, everytime you managed to get it to boot up, it would ALWAYS ask you to input the date and time from dos. The same thing happened after we got the battery replaced and got it working. I believe the battery keeps power to the EEPROM or BIOS chips as swoopy said.Ok, where's all the PC hardware experts out there? Help us out.
I would think this "seconds since jan 1st 1970" is stored in some nonvolatile memory, like EEPROM, unless they use a battery to keep the clock running.
Alls I know is in the last few moments of the caputer's life, it had a nice shinny thing inside that said Energizer on it.
The world is waiting. I must leave you now.