-
July 15th, 2013, 01:17 PM
#1
UnixTimestamp to time
I have the following code that takes a unix time stamp into a date.
Code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
//e.g. 1331812987 = Thu 15 Mar 2012 01:03:07 PM CET
int main(int argc, char** argv) {
struct tm * dt;
char b[19];
long ts;
ts = 1331812987;
dt = localtime(&ts);
// use any strftime format spec here
strftime(b, sizeof(b), "%c", dt);
fprintf(stdout, "%s", b);
getch();
return 0;
}
Everything is right accept the HOUR of the timestamp which is 07 instead of 01
is this fixable?
-
July 15th, 2013, 01:35 PM
#2
Re: UnixTimestamp to time
Originally Posted by vaas
I have the following code that takes a unix time stamp into a date.
Code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
//e.g. 1331812987 = Thu 15 Mar 2012 01:03:07 PM CET
int main(int argc, char** argv) {
struct tm * dt;
char b[19];
long ts;
ts = 1331812987;
dt = localtime(&ts);
// use any strftime format spec here
strftime(b, sizeof(b), "%c", dt);
fprintf(stdout, "%s", b);
getch();
return 0;
}
Everything is right accept the HOUR of the timestamp which is 07 instead of 01
is this fixable?
According to http://www.unixtimestamp.com/index.php, 7 is the correct hour. Looks like it may be adjusting to the time zone of the computer.
-
July 16th, 2013, 04:53 AM
#3
Re: UnixTimestamp to time
Yes localtime is returning the local time
If you don't want that use gmtime instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|