计算机纪元 时间戳_如何在C中获取纪元时间戳?

计算机纪元 时间戳

In C, how to get the epoch timestamp, the number of seconds passed since the epoch?

C中 ,如何获取新纪元时间戳,即自新纪元以来经过的秒数?

In C, from man 7 time:

C中 ,距man 7 time

UNIX systems represent time in seconds since the Epoch, 1970-01-01
00:00:00 +0000 (UTC).

自1970年1月1日以来,UNIX 系统以秒为单位表示时间
00:00:00 +0000(UTC)。

A program can determine the calendar time using gettimeofday(2), which
returns time (in seconds and microseconds) that have elapsed since the
Epoch; time(2) provides similar information, but only with accuracy to
the nearest second.

程序可以使用gettimeofday(2)确定日历时间,
返回自从开始到现在的时间(以秒和微秒为单位)
时代; time(2)提供类似的信息,但仅具有
最近的秒。

You can use the time() library function to get the epoch timestamp:

您可以使用time()库函数获取纪元时间戳:

On 32-bit POSIX systems:

在32位POSIX系统上:

fprintf(stdout, "%un", (unsigned)time(NULL));

On 64-bit POSIX systems:

在64位POSIX系统上:

fprintf(stdout, "%lun", (unsigned long)time(NULL));
Answered by dtivl.
dtivl回答。

翻译自: https://www.systutorials.com/how-to-get-the-epoch-timestamp-in-c/

计算机纪元 时间戳

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值