' date ' part from unix timestamp is not correct

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • summary

    ' date ' part from unix timestamp is not correct

    I am reading a log file & storing the values into a structure

    Code:
    struct mylog{
    
      int sno;
      time_t time_seconds;
      long poscode;
      //....
      //....
    };
    but while reading data from log & converting it into time value i am getting wrong values of date part but correct values for time part.

    Code:
    bar=time(&(logdata->time_second));
    
    
    printf("\n%lu -> %s", logdata->time_second, asctime(gmtime(&(logdata->time_second))));
    
    printf( "%s ",ctime(&bar));
    logdata is the pointer to struct mylog.

    i checked with both ctime & asctime too both are giving wrong date part but correct time part

    I checked that value coming in logdata->time_second = 347533824
    I guess it should be 10 digits.
    Am i correct .
    Please help me in this regard.

    Thanks in advance.
    Last edited by Frinavale; Oct 25 '10, 07:52 PM. Reason: Added code tags
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    It would help if you told us what the actual output was and what you expected the output to be.

    1. The size and encoding of type time_t is implementation dependent. Are you sure that the system that prints the log is compatible with the system that wrote the log?

    2. gmtime gives you the date and time in London. Might the discrepancy you are seeing be due to your expectation that the time would be for your local time zone? How many hours difference is there between your time zone and GMT?

    3. struct mylog has a field called log_seconds, but your executable code refers to field log_second. Presumably this discrepancy is just a typo.

    4. Are you sure the system writing the log was aware the correct date?

    Comment

    Working...