linux下用来修改系统时间的函数

本文介绍如何使用gettimeofday和settimeofday函数获取与设置系统的当前时间。这些函数通过timeval结构体来表达从1970年1月1日00:00起经过的秒数和微秒数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Standard C Library Functions                     gettimeofday(3C)

NAME
     gettimeofday, settimeofday - get or set the date and time

SYNOPSIS
     #include <sys/time.h>

#include <unistd.h>

 

     int gettimeofday(struct timeval *tp, void *);

     int settimeofday(struct timeval *tp, void *);

DESCRIPTION
     The gettimeofday()  function  gets  and  the  settimeofday()
     function  sets  the system's notion of the current time. The
     current  time  is   expressed   in   elapsed   seconds   and
     microseconds since 00:00 Universal Coordinated Time, January
     1, 1970. The resolution of  the  system  clock  is  hardware
     dependent;  the time may be updated continuously or in clock
     ticks.

     The  tp  argument  points  to  a  timeval  structure,  which
     includes the following members:

     long    tv_sec;    /* seconds since Jan. 1, 1970 */
     long    tv_usec;   /* and microseconds */

     If tp is a null pointer, the current time information is not
     returned or set.

     The TZ environment variable holds time zone information. See
     TIMEZONE(4).

     The second argument  to  gettimeofday()  and  settimeofday()
     should be a pointer to NULL.

     Only the super-user may set the time of day.

RETURN VALUES
     Upon successful completion, 0 is returned.  Otherwise, -1 is
     returned and errno is set to indicate the error.

 

settimeofday(const struct timeval * t , const struct timezone *tzv )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值