convert unix long time to get hour

This is a discussion on convert unix long time to get hour within the C Programming forums, part of the General Programming Boards category; Hi, Can anyone tell me the function in C that converts unix long time (ex: 1020830400) to get hour, min, ...

  1. #1
    huskers
    Guest

    convert unix long time to get hour

    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

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    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

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #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;
    }
    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59
    hmm
    " programming is 1% syntax and 99% logic "

  6. #6
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > hmm

    Ok, I'm sorry. What's the point of these posts?
    The world is waiting. I must leave you now.

  7. #7
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    759
    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

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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.
    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:
    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 05:25 PM.

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > 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.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >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.

  11. #11
    My diaper's full....... stevey's Avatar
    Join Date
    Nov 2001
    Posts
    759
    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 08:11 PM.
    Steve

  12. #12
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    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.
    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.

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 12:29 PM
  2. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 08:51 PM
  3. Sorting Algorithms with Time
    By silicon in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2005, 12:27 PM
  4. cannot convert from HBITMAP__* to unsigned long
    By Leeman_s in forum Windows Programming
    Replies: 1
    Last Post: 01-05-2003, 07:49 PM
  5. need help
    By emperor in forum C Programming
    Replies: 1
    Last Post: 03-04-2002, 12:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21