QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2165|回复: 4

为什么时钟的时间基准是1970年1月1日?

[复制链接]
发表于 2003-5-28 20:42:17 | 显示全部楼层 |阅读模式
为什么时钟的时间基准是1970年1月1日,而不是别的时间呢?

如果不使用统一的时间基准不行吗,比如我修改系统时间的时候是2003-5-20,那么以后的时间就都以这个时间来推算不就行了吗?还用的着那么费事去计算和1970-1-1差多少秒?
发表于 2003-5-28 21:34:02 | 显示全部楼层
1970年1月1日 is defined by some unix i guess. maybe posix also has it, but i am not sure.

then how about the file before this time? how to compute?
回复

使用道具 举报

发表于 2003-5-28 22:50:13 | 显示全部楼层
它返回的是当前时刻(距离1970年的秒数),是一个32位值,会在将来溢出的

几乎所有的操作系统包括windows都有这个函数
回复

使用道具 举报

发表于 2003-5-29 00:08:01 | 显示全部楼层
我想可能是这样
因为unix是1969年以后才有的,所以并不存在一个file是之前在unix上创建
溢出时间是准确的时间为2038年一月十八日星期一晚上十点十四分七秒。那一刻,时间将会转为负数,变成1901年十二月十三日黑色星期五下午三点四十五分五十二秒,这就是所谓的UNIX 2038 BUG
回复

使用道具 举报

发表于 2003-5-29 03:12:31 | 显示全部楼层
use this perl script to check if u system has this problem. but in fact, i believe almost all systems will be upgrade to 64bit at the time (if we still have chance to do that before the world is end), then no this bug at all.

#!/usr/local/bin/perl

use POSIX;
$ENV{'TZ'} = "GMT";

for ($clock = 2147483641; $clock < 2147483651; $clock++) {
        print ctime($clock);
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-16 04:18 , Processed in 0.095056 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表