localtime

This is a discussion on localtime within the C Programming forums, part of the General Programming Boards category; i need a time in 24 hours format but ima getting in 12hours format i tried this Code: int main() ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    90

    localtime

    i need a time in 24 hours format but ima getting in 12hours format
    i tried this
    Code:
    int main()
    {
    time_t now;
    if ( time(&now) != (time_t)(-1) )
    {
            struct tm *mytime = localtime(&now);
            if ( mytime )
         {
            
              if ( strftime(tim, sizeof tim, "%X", mytime) )
              {
                printf("time = \"%s\"\n", tim);
              }
         }
    }
    return 0;
    }
    iam getting 10:30:40 PM
    wht i need is 22:30:40
    how can i do this

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    Use some other time formatting letters I guess.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. localtime curiosity
    By rjhanby in forum C Programming
    Replies: 5
    Last Post: 03-20-2009, 10:15 AM
  2. Converting localtime seconds into float
    By superpickle in forum C Programming
    Replies: 2
    Last Post: 05-12-2007, 05:09 PM
  3. localtime and time
    By l2u in forum C Programming
    Replies: 5
    Last Post: 07-24-2006, 12:10 PM
  4. getting LocalTime
    By Devil Panther in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2003, 05:41 AM
  5. localtime(), time(). What happened?
    By Nutka in forum C Programming
    Replies: 7
    Last Post: 12-10-2002, 05:22 AM

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