Swift: convert NSDate to c# ticks

前端 未结 2 1542
暖寄归人
暖寄归人 2020-12-12 07:10

i need to convert a NSDate to C# ticks.

DateTime.ticks converts date to ticks starting from January 1 0001.

How can i do that? Thanks in advance.

2条回答
  •  感情败类
    2020-12-12 07:34

    I borrowed this code somewhere, so I'm not an author. Here it goes:

       @implementation NSDate (Ticks)
    
        - (long long) ticks
        {
            double tickFactor = 10000000;
            long long tickValue = (long long)floor([self timeIntervalSince1970] * tickFactor) + 621355968000000000LL;
            return tickValue;
        }
    
        + (NSDate*) dateWithTicks:(long long)ticks
        {
            double tickFactor = 10000000;
            double seconds = (ticks - 621355968000000000LL) / tickFactor;
            return [NSDate dateWithTimeIntervalSince1970:seconds];
        }
    
        @end
    

提交回复
热议问题