How to convert Datetime to UInt32

X

XingZheng

Hi
This is the code in Visual C++

time_t timeNow;
UINT nSeed = time(&timeNow);

How to get nSeed in C# when we have DateTime.Now?
 
M

Mattias Sjögren

This is the code in Visual C++

time_t timeNow;
UINT nSeed = time(&timeNow);

How to get nSeed in C# when we have DateTime.Now?

time_t contains the number of seconds since midnight 1/1/1970, so
something like this may give you what you want

TimeSpan ts = DateTime.Now - new DateTime( 1970, 1, 1 );
uint nSeed = (uint)ts.TotalSeconds;



Mattias
 
R

Remigiusz Samosiuk

if you can use long type instead of uint32 there is Ticks property

From MSDN:

public long Ticks {get;}

The value of this property is the number of 100-nanosecond intervals that
have elapsed since 12:00 A.M., January 1, 0001.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top