tags:

views:

23

answers:

2

Hello everybody!

Can anyone tell me how can I convert a value which I know to be CFAbsoluteTime from MacOS into DateTime value in C#?

A: 

It turned out, that I can convert it using following code:

TimeSpan span = TimeSpan.FromSeconds(CFAbsoluteTimeFloatValue);
var cshartpDateTime = new DateTime(2001, 1, 1).Add(span);
DarkDeny
+1  A: 

A CFAbsoluteTime is a double, the number of seconds since January 1st, 2001, 12am. Thus:

    public static DateTime CFAbsoluteTimeToDateTime(double abs) {
        long ticks = (long)(abs * 1E7);  // 1 tick == 100 nsec
        return new DateTime(new DateTime(2001, 1, 1).Ticks + ticks);
    }
Hans Passant