我想我今天写的一些软件将在30年内使用.但我也意识到,很多都是基于UNIX传统,即将时间暴露为自1970年以来的秒数.
#include <stdio.h>
#include <time.h>
#include <limits.h>
void print(time_t rt) {
struct tm * t = gmtime(&rt);
puts(asctime(t));
}
int main() {
print(0);
print(time(0));
print(LONG_MAX);
print(LONG_MAX+1);
}
Run Code Online (Sandbox Code Playgroud)
执行结果:
函数ctime(),gmtime()和localtime()都将一个时间值作为参数,该时间值表示自Epoch(1970年1月1日00:00:00 UTC;参见时间(3))以来的时间(以秒为单位).
我想知道作为程序员在这个领域是否有任何主动做的事情,或者我们是否相信所有软件系统(又称操作系统)将来会如何神奇地升级?
更新看起来确实64位系统是安全的:
import java.util.*;
class TimeTest {
public static void main(String[] args) {
print(0);
print(System.currentTimeMillis());
print(Long.MAX_VALUE);
print(Long.MAX_VALUE + 1);
}
static void print(long l) {
System.out.println(new Date(l));
}
}
Run Code Online (Sandbox Code Playgroud)
但那一年292278994呢?
我使用这个使用 pyatspi ( from pyatspi import \xe2\x80\xa6) 的 python 库。当我在 (L)Ubuntu 16.04 中运行它时,它会抛出以下错误:
/usr/lib/python2.7/dist-packages/pyatspi/__init__.py:17: PyGIWarning: Atspi was imported without specifying a version first. Use gi.require_version(\'Atspi\', \'2.0\') before import to ensure that the right version gets loaded.\n from gi.repository import Atspi\nRun Code Online (Sandbox Code Playgroud)\n\n尽管此错误消息准确地说明了我应该做什么,但仅gi.require_version(\'Atspi\', \'2.0\')在/usr/lib/python2.7/dist-packages/pyatspi/__init__.py(giving NameError: name \'gi\' is not defined) \xe2\x80\x93 中添加行是行不通的,我做错了什么?