Swift:将NSDate转换为c#ticks [英] Swift: convert NSDate to c# ticks

查看:143
本文介绍了Swift:将NSDate转换为c#ticks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将NSDate转换为C#ticks。

i need to convert a NSDate to C# ticks.

DateTime.ticks将日期转换为从0001年1月1日起的刻度。

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

我该怎么办?
提前感谢。

How can i do that? Thanks in advance.

推荐答案

我在这里借了这段代码,所以我不是作者。在这里:

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

这篇关于Swift:将NSDate转换为c#ticks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆