How to determine curreent date and time/

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sanchit

    How to determine curreent date and time/

    I am using GCC on FEDORA.

    I want to print current date an time. How can do that.

    Thanks
    -Sanchit
  • Antoninus Twink

    #2
    Re: How to determine curreent date and time/

    On 14 Apr 2008 at 17:14, Sanchit wrote:
    I am using GCC on FEDORA.
    >
    I want to print current date an time. How can do that.
    system("date");

    Comment

    • Sanchit

      #3
      Re: How to determine curreent date and time/

      On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam. invalidwrote:
      On 14 Apr 2008 at 17:14, Sanchit wrote:
      >
      I am using GCC on FEDORA.
      >
      I want to print current date an time. How can do that.
      >
      system("date");
      Oh I forgot to mention.. I want a C function for this.

      Comment

      • Antoninus Twink

        #4
        Re: How to determine curreent date and time/

        On 14 Apr 2008 at 17:39, Sanchit wrote:
        On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam. invalidwrote:
        >On 14 Apr 2008 at 17:14, Sanchit wrote:
        >>
        I am using GCC on FEDORA.
        >>
        I want to print current date an time. How can do that.
        >>
        >system("date") ;
        >
        Oh I forgot to mention.. I want a C function for this.
        strftime?

        Comment

        • aspinall@oltrelinux.com

          #5
          Re: How to determine curreent date and time/

          On 14 Apr, 19:14, Sanchit <sanchitgupt... @gmail.comwrote :
          I am using GCC on FEDORA.
          >
          I want to print current date an time. How can do that.
          #include <time.h>
          #include <stdio.h>
          #include <stdlib.h>

          int main(){

          time_t now = time(NULL);
          struct tm *now_s = localtime(&now) ;

          if(now_s == NULL)
          return EXIT_FAILURE;

          printf("%d-%02d-%02d %02d:%02d:%02d\ n", 1900+now_s->tm_year, ++now_s -
          >tm_mon,
          now_s->tm_mday, now_s->tm_hour, now_s->tm_min,now_s->tm_sec);

          return EXIT_SUCCESS;
          }

          Bye.

          Comment

          • Gordon Burditt

            #6
            Re: How to determine curreent date and time/

            >I am using GCC on FEDORA.
            >
            >I want to print current date an time. How can do that.
            In C, time() gets you the current date/time in a time_t format.
            Various functions can get that into a printable string format:

            ctime()
            localtime() followed by strftime()
            localtime() followed by asctime()


            Comment

            • harsha

              #7
              Re: How to determine curreent date and time/

              On Apr 14, 10:39 pm, Sanchit <sanchitgupt... @gmail.comwrote :
              On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam. invalidwrote:
              >
              On 14 Apr 2008 at 17:14, Sanchit wrote:
              >
              I am using GCC on FEDORA.
              >
              I want to print current date an time. How can do that.
              >
              system("date");
              >
              Oh I forgot to mention.. I want a C function for this.

              Comment

              Working...