Thread: Converting localtime seconds into float

  1. #1
    Registered User
    Join Date
    May 2006

    Converting localtime seconds into float

    I am trying to make a program that reads the seconds from the system time and prints them on the screen. However, the seconds always seem to be in integer format and I wish to use it in floating point format instead, i.e. to display milliseconds. Is this possible?

    Here is the current program I am using. It's similar to the one found on the time_t page at Wikipedia.

    #include <stdio.h>
    #include <time.h>
        time_t     now;
        struct tm  ts;
        char       buf[80];
        ts = *localtime(&now);
        strftime(buf, sizeof(buf), "%S", &ts);
        printf("%s\n", buf);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Why not just access the tm_sec member variable of ts ?

    Also, I don't think you're going to get any meaningful milliseconds out of this.
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    I believe you're dreaming big time with millseconds.

    In any case, they would be printed (and printed over), far faster than anyone could see what they were.

    I'd suggest using 1/10'ths of a second as your shortest timer interval.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM