質問

I would like to use next code:

long long DateTimeToTimeT(System::DateTime dt)
{
    System::DateTime epoch(1970, 1, 1, 0, 0, 0, 0);
    long long totalSeconds = (dt - epoch).TotalSeconds;

    return totalSeconds >= 0 ? totalSeconds : 0;
}

So question is: Is it exception safe or I should handle some errors here?

I mean: Is is safe to convert from double (which is TotalSeconds) to long long in such case?

正しい解決策はありません

他のヒント

Yes, it is safe: the subtraction of two dates never throws (http://msdn.microsoft.com/en-us/library/1905yhe2(v=vs.110).aspx) since TimeSpan covers a much larger interval than valid dates.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top