date command

This is a discussion on date command within the C Programming forums, part of the General Programming Boards category; is there a way i can display time(only) in hh:mm:ss format within a c code i use ubuntu and i ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    12

    date command

    is there a way i can display time(only) in hh:mm:ss format within a c code

    i use ubuntu and i tried date command in linux within a printf command but it did not work

    what is missing here

    i'm new to this fourm and bit new to c programming

    any helpful tutorial links?

    thank you

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    40

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    12
    it's bit complex to understand, is there any tutorial that has good explanation with the codeing
    thnx

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    on Linux I'd use gettimeofday().

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    12
    Quote Originally Posted by Kennedy
    on Linux I'd use gettimeofday().
    is that command can be use in a c code

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    40
    should help: http://www.cplusplus.com/reference/c...ime/ctime.html

    the function ctime() returns a c-style string. Instead of printing the returned value like in the example, you can store that into a c-style string variable and parse through it to find hh:mm:ss

  7. #7
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    look up the strftime function.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Code:
    char *str;
    
    timer=time(NULL);
    str = asctime(localtime(&timer));
    str = str+11;
    printf("%*.*s\n",0,9,str);
    you could do something like this. But strftime would be recommended

    ssharish2005

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by kusal
    is there a way i can display time(only) in hh:mm:ss format within a c code
    http://cboard.cprogramming.com/showthread.php?p=368715
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  3. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

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