Reputation: 41
I need some help casting a big double to int, in java:
(int)System.currentTimeMillis(); //result -186983989 (java)
The result always return the int32.minvalue, but I need the same result as java. but in C#:
DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
TimeSpan span = DateTime.UtcNow - Jan1st1970;
Int32 resultado = (int)span.TotalMilliseconds; //result is always -2147483648 and i need same as java
Thanks in advance, can see this image https://public.blu.livefilestore.com/y1pwU6fnT0v663NPqa7cSwwU9MSFQeO1TjdOdip1GFn8Eqg0Fgo_rsA3ER2jw5RDpXGOa1WiMc_PFIzzjxkqWe9zQ/wtf.png?psid=1.
Upvotes: 0
Views: 221
Reputation: 837926
An int
has a range of -2,147,483,648 to 2,147,483,647. The result is much larger than this. You'll need a larger data type with a larger range. Try long
instead of int
.
long resultado = (long)span.TotalMilliseconds;
Result:
resultado 1335553169530 long
Upvotes: 2