python - obj-C 与 python 中的 Unix 时间

标签 python objective-c

我正在比较我的函数以获取 Obj-C 和 python 中的时间戳。下面是两个函数:

// Obj-C
NSTimeInterval secondsSinceUnixEpoch = [[NSDate date] timeIntervalSince1970];
double nonceLng = (double)(secondsSinceUnixEpoch) * 1000000;
NSString *nonce = [NSString stringWithFormat: @"%.0f", nonceLng];
NSLog(nonce);
==> 1422379701020979

// Python
>>> int(time.time()*1e6)
==> 1422379701239615

有没有办法让Obj-C部分更紧凑?或者,上面的方法真的可以做到吗?

最佳答案

您的 Python 代码全部在一行中,但您将 Objective-C 代码分成了三行。 Python 代码似乎以某种整数形式返回值,但您的 Objective-C 代码会将数字转换为字符串。

当您需要显式 NSLog 来查看 Objective-C 值时,Python 控制台会自动记录结果。

所以试试这个:

long long timestamp = [[NSDate date] timeIntervalSince1970] * 1000000;
NSLog(@"%lld", timestamp);

不算 NSLog,它现在更具可比性。

关于python - obj-C 与 python 中的 Unix 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28176408/

相关文章:

iphone - ERROR : You are not the current participant. 当我是当前参与者时。什么?

ios - 为什么我的应用程序在从 NSUserDefaults 加载数组时崩溃?

iphone - AdMob 崩溃并显示 [GADObjectPrivate changeState :]: unrecognized selector

python - 从文件加载特定的 PyYAML 文档

python - 将 float64 列转换为日期时间 pandas 时出错

python - 如果其中一个为真,我该如何停止 for 语句? Python

iphone - 如何将 3d View 旋转 360 度?

python - VSCode Pylance 自动导入只提示输入

Python编码unicode<>utf-8

objective-c - 如何在 UIImageView 上方显示一个不可见的交互按钮