Reputation: 11908
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?
Upvotes: 9
Views: 15750
Reputation: 8844
Bastardo's solution did not help me. I was facing an issue with DST, so an additional conversion to local time was required, or the resulting time differed by one hour. This is what I do:
return new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(time_t);
Upvotes: 3
Reputation: 4152
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
Upvotes: 11
Reputation: 90995
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.
Upvotes: 8
Reputation: 15286
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).
Upvotes: 3