搜索
bottom↓
回复: 5

请教标准库 time_t time(time_t *seconds)如何使用?

[复制链接]

出0入10汤圆

发表于 2021-6-3 13:38:01 | 显示全部楼层 |阅读模式
请教标准库 time_t time(time_t *seconds)如何使用?
我的理解这种函数返回值和参数是一样功能,对的吗
参数得到的值和返回值有区别吗?

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出215入169汤圆

发表于 2021-6-3 13:47:51 | 显示全部楼层
本帖最后由 monkeynav 于 2021-6-3 13:50 编辑

https://www.cplusplus.com/reference/ctime/time/
https://linux.die.net/man/2/time

不用上网就可以查文档了。在linux主机输入man 2 time:
楼主理解没错,指针保存的值和返回值一样的。

TIME(2)                                                                                                Linux Programmer's Manual                                                                                                TIME(2)

NAME
       time - get time in seconds

SYNOPSIS
       #include <time.h>

       time_t time(time_t *tloc);

DESCRIPTION
       time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).

       If tloc is non-NULL, the return value is also stored in the memory pointed to by tloc.

RETURN VALUE
       On success, the value of time in seconds since the Epoch is returned.  On error, ((time_t) -1) is returned, and errno is set appropriately.

ERRORS
       EFAULT tloc points outside your accessible address space (but see BUGS).

              On systems where the C library time() wrapper function invokes an implementation provided by the vdso(7) (so that there is no trap into the kernel), an invalid address may instead trigger a SIGSEGV signal.

CONFORMING TO
       SVr4, 4.3BSD, C89, C99, POSIX.1-2001.  POSIX does not specify any error conditions.

NOTES
       POSIX.1  defines  seconds since the Epoch using a formula that approximates the number of seconds between a specified time and the Epoch.  This formula takes account of the facts that all years that are evenly divisible by 4
       are leap years, but years that are evenly divisible by 100 are not leap years unless they are also evenly divisible by 400, in which case they are leap years.  This value is not the same  as  the  actual  number  of  seconds
       between  the  time  and the Epoch, because of leap seconds and because system clock.s are not required to be synchronized to a standard reference.  The intention is that the interpretation of seconds since the Epoch values be
       consistent; see POSIX.1-2008 Rationale A.4.15 for further rationale.

       On Linux, a call to time() with tloc specified as NULL cannot fail with the error EOVERFLOW, even on ABIs where time_t is a signed 32-bit integer and the clock tick.s past the time 2**31  (2038-01-19  03:14:08  UTC,  ignoring
       leap  seconds).   (POSIX.1 permits, but does not require, the EOVERFLOW error in the case where the seconds since the Epoch will not fit in time_t.)  Instead, the behavior on Linux is undefined when the system time is out of
       the time_t range.  Applications intended to run after 2038 should use ABIs with time_t wider than 32 bits.

BUGS
       Error returns from this system call are indistinguishable from successful reports that the time is a few seconds before the Epoch, so the C library wrapper function never sets errno as a result of this call.

       The tloc argument is obsolescent and should always be NULL in new code.  When tloc is NULL, the call cannot fail.

SEE ALSO
       date(1), gettimeofday(2), ctime(3), ftime(3), time(7), vdso(7)

COLOPHON
       This page is part of release 4.04 of the Linux man-pages project.  A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.

出200入2554汤圆

发表于 2021-6-3 14:00:22 | 显示全部楼层
MSDN 摘一段,微软的文档不错:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入10汤圆

 楼主| 发表于 2021-6-3 14:03:03 来自手机 | 显示全部楼层
英文不好

出0入8汤圆

发表于 2021-6-3 14:20:02 来自手机 | 显示全部楼层
硬邦邦 发表于 2021-6-3 14:03
英文不好

可以淘宝付费找人帮你解读API,2块钱一个,我经常用,节约了大量时间

出0入362汤圆

发表于 2021-6-4 16:14:22 | 显示全部楼层
我从来都是time_t now = time(0);
没报过错
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-16 14:27

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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