cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : Get seconds from 1970
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  Get seconds from 1970

Gang
Hello, I have some problem.
I need to calculate how many seconds gone since 1970.
I used tm structure and mktime()function, but I have wrong results. Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <vcl.h>
#include <time.h>

struct tm t;
time_t t1,t2;

void __fastcall TForm1::Button1Click(TObject *Sender)
{

    t.tm_year = 2008-1900;
    t.tm_mon = 3;
    t.tm_mday = 9;
    t.tm_hour = 16;
    t.tm_min = 39;
    t.tm_sec = 42;
    t.tm_isdst = 0;
    t1=mktime(&t);

    Memo1->Lines->Add(IntToStr(t1));
    Memo1->Lines->Add(ctime(&t1));
}

I`ve got 1207748382 instead of 3416917182.
What I`am doing wrong?
Thx for the help )
|
Zaita
Edit. Easier way.

http://www.cplusplus.com/reference/clibrary/ctime/difftime.html





| Last edited on

Registered users can reply in this forum.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us