Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is c time_t equivalent for c#

Tags:

c

c#

types

time

There is a native method from dll written in c which takes a parameter of type time_t. Is it possible to use C# uint or ulong for this parameter?

like image 986
Sergey Avatar asked Jun 08 '11 06:06

Sergey


3 Answers

I do not think I should say they are equivalent, but you can convert t_time to DateTime in such a way:

 int t= 1070390676; // value of time_t in an ordinary integer
 System.DateTime dt= new System.DateTime(1970,1,1).AddSeconds(t); 

And this example is from How can I convert date-time data in time_t to C# DateTime class format?

I should also say that UInt32 is used for t_time,too.check DateTime to time_t

like image 157
Bastardo Avatar answered Sep 22 '22 21:09

Bastardo


Depends on how time_t was defined in the Standard C header files the DLL was compiled against.

If time_t is 64-bit, the C# equivalent is long.

If time_t is 32-bit, then it has the Year 2038 bug and you should ask whoever wrote the DLL for a non-buggy version.

like image 37
dan04 Avatar answered Sep 22 '22 21:09

dan04


According to Wikipedia's article on Time_t you could use a integer (Int32 or Int64)

Unix and POSIX-compliant systems implement time_t as an integer or real-floating type (typically a 32- or 64-bit integer) which represents the number of seconds since the start of the Unix epoch: midnight UTC of January 1, 1970 (not counting leap seconds).

like image 40
Jonas Stensved Avatar answered Sep 23 '22 21:09

Jonas Stensved