Date

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

    Date

    Greetings, i know to get all the dates/times one would use the header ctime
    or time.h.
    Can some one then direct me in the right direction to actually get the date
    or anything.

    Many thanks!


  • John Harrison

    #2
    Re: Date


    "Paul Selibas" <nospam@mweb.co .za> wrote in message
    news:3f1b025a.0 @news1.mweb.co. za...[color=blue]
    > Greetings, i know to get all the dates/times one would use the header[/color]
    ctime[color=blue]
    > or time.h.
    > Can some one then direct me in the right direction to actually get the[/color]
    date[color=blue]
    > or anything.
    >
    > Many thanks!
    >[/color]

    Time functions are tricky to handle. Something like this should work
    (untested)

    #include <time.h>

    tm time = *localtime(time (0));
    cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
    time.tm_year + 1900;

    This prints the date British style (i.e. day / month / year).

    john


    Comment

    • John Harrison

      #3
      Re: Date

      >[color=blue]
      > Time functions are tricky to handle. Something like this should work
      > (untested)
      >
      > #include <time.h>
      >
      > tm time = *localtime(time (0));
      > cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
      > time.tm_year + 1900;
      >
      > This prints the date British style (i.e. day / month / year).
      >
      > john[/color]

      Apologies, I said they were tricky. Try this

      time_t t = time(0);
      tm time = *localtime(&t);
      cout << "The date is " << time.tm_mday << '/' << time.tm_mon + 1 << '/' <<
      time.tm_year + 1900;

      john


      Comment

      Working...