Which is equivalent to c time_t for C #

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?

+6
source share
4 answers

Depending on how time_t was defined in the Standard C header files, the DLL was compiled.

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

If time_t is 32-bit, then it has a 2038 error, and you should ask who would not write a DLL for the non-buggy version.

+6
source

I don't think I have to say that they are equivalent, but you can convert t_time to DateTime in this 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 from How to convert date and time data in time_t to C # DateTime format?

I should also say that UInt32 used for t_ time , too.check DateTime to time_t

+7
source

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

Unix and POSIX compatible systems implement time_t as an integer or real floating-point type (usually a 32-bit or 64-bit integer), which is the number of seconds since the start of the Unix era: midnight UTC on January 1, 1970 (not counting the seconds of the jump) .

+2
source

Bastardo's decision did not help me. I ran into a problem with DST, so extra conversion to local time was required, or the resulting time was one hour different. This is what I do:

 return new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(time_t); 
0
source

Source: https://habr.com/ru/post/890025/


All Articles