hellp about local timestamp

Discussion in 'C++' started by Zhaohui, Dec 7, 2005.

  1. Zhaohui

    Zhaohui Guest

    hello everyone:

    How can I get local timestamp use c++/c, I only know is time(), but
    time() returns a UTC timestamp, I want get local timestamp, how can
    I do, I am under windows system.

    thanks.

    Zhaohui
     
    Zhaohui, Dec 7, 2005
    #1
    1. Advertising

  2. * Zhaohui:
    > hello everyone:
    >
    > How can I get local timestamp use c++/c, I only know is time(), but
    > time() returns a UTC timestamp, I want get local timestamp, how can
    > I do, I am under windows system.


    I would check the documentation.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Dec 7, 2005
    #2
    1. Advertising

  3. Zhaohui

    Guest

    Its a bit off topic here, but look at localtime_r at POSIX/BSD systems.
     
    , Dec 7, 2005
    #3
  4. Zhaohui

    babi Guest

    Hi,
    Have a look at this program which may help you.
    I tried to print the time.

    Thanks & Regds,
    T.Mohanta

    cat time.c

    #include <stdio.h>
    #include <sys/time.h>
    #include <time.h>
    #include <unistd.h>

    void print_time ()
    {
    struct timeval tv;
    struct tm* ptm;
    char time_string[40];
    long milliseconds;
    double sec;
    double secs;

    /* Obtain the time of day, and convert it to a tm struct.
    */
    gettimeofday (&tv, NULL);
    ptm = localtime (&tv.tv_sec);
    /* Format the date and time, down to a single second. */
    strftime (time_string, sizeof (time_string), "%Y-%m-%d
    %H:%M:%S",
    ptm);
    /* Compute milliseconds from microseconds. */
    milliseconds = tv.tv_usec / 1000;
    sec = tv.tv_sec;
    /* Print the formatted time, in seconds, followed by a
    decimal
    point
    * and the milliseconds. */

    printf ("The sec--- value %d\n", sec);
    printf ("%s\n", time_string);
    printf ("The sec value %d\n", ptm->tm_sec);
    printf ("%s.%03ld\n", time_string, milliseconds);
    printf ("The min value ======%d\n", ptm->tm_min);
    //printf ("%s.%03ld\n", time_string, milliseconds);
    printf ("%d\n", time_string, milliseconds);
    sleep(2);
    gettimeofday (&tv, NULL);
    secs = tv.tv_sec;
    ptm = localtime (&tv.tv_sec);
    /* Format the date and time, down to a single second. */
    strftime (time_string, sizeof (time_string), "%Y-%m-%d
    %H:%M:%S",
    ptm);
    milliseconds = tv.tv_usec / 1000;
    printf ("%s.%03ld\n", time_string, milliseconds);
    printf ("The sec--- value %d\n", secs);
    printf ("The sec value %d\n", ptm->tm_sec);
    printf ("The min value %d\n", ptm->tm_min);
    printf ("The diff value %d\n", (secs-sec));
    }
    int main ()
    {
    print_time();
    return 0;
    }
     
    babi, Dec 7, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    1
    Views:
    791
    George Ter-Saakov
    Jun 26, 2003
  2. =?Utf-8?B?WVNVVA==?=

    Access local port or Running local exe file

    =?Utf-8?B?WVNVVA==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    535
    =?Utf-8?B?WVNVVA==?=
    Jan 14, 2006
  3. Jim in Arizona
    Replies:
    8
    Views:
    5,003
    Jim in Arizona
    Jan 24, 2006
  4. Hellp with type promotion

    , Feb 28, 2006, in forum: C Programming
    Replies:
    10
    Views:
    548
    Dave Thompson
    Mar 6, 2006
  5. fulio pen

    Please hellp again with a code

    fulio pen, Aug 22, 2005, in forum: Javascript
    Replies:
    0
    Views:
    84
    fulio pen
    Aug 22, 2005
Loading...

Share This Page