Time function

This is a discussion on Time function within the C Programming forums, part of the General Programming Boards category; I am working with time function and what I inderstand is that if you have now=time(NULL) and you output time ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    124

    Time function

    I am working with time function and what I inderstand is that if you have now=time(NULL) and you output time you will get the number of seconds that have passed since Jan, 01, 1970. Please correct me if I am wrong on this.
    What I am trying to do is have a user input a date and for the program to count seconds from that date. What would now variable have to equal to in this case ?
    Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Depends on the input. Perhaps some date functions can help you?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Please correct me if I am wrong on this.
    The value is the current time, whose value and representation remain unknown to you. It doesn't have to be seconds since the Unix epoch, so you should refrain from relying on that.

    >What would now variable have to equal to in this case ?
    You shouldn't diddle with time_t. Instead, use the tm struct. You can fill up the members of that structure and then use mktime to portably build a time_t value. From there you can use difftime to get a count of seconds.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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