By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

' date ' part from unix timestamp is not correct

P: n/a
I am reading a log file & storing the values into a structure

Expand|Select|Wrap|Line Numbers
  1. struct mylog{
  3.   int sno;
  4.   time_t time_seconds;
  5.   long poscode;
  6.   //....
  7.   //....
  8. };
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.

Expand|Select|Wrap|Line Numbers
  2. bar=time(&(logdata->time_second));
  5. printf("\n%lu -> %s", logdata->time_second, asctime(gmtime(&(logdata->time_second))));
  7. 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.
Oct 25 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 2,398
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?
Oct 25 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.