linux下的时间编程

linux下的时间编程

日历时间
time:
    原型:time_t time(time_t *tloc);
	返回值:从1970-01-01 00:00:00 +0000 到现在的秒数,如果tloc为非空,返回值也会存储到tloc指向的内存中
本地时间
// 本地时间
struct tm *localtime(const time_t *timep);
// 格林威治时间
struct tm *gmtime(const time_t *timep);
// SACLL时间
char *ctime(const time_t *timep);

char *asctime(const struct tm *tm);

time_t mktime(struct tm *tm);
size_t strftime(char *s, size_t max, const char *format,
               const struct tm *tm);
struct tm {
       int tm_sec;    /* Seconds (0-60) */
       int tm_min;    /* Minutes (0-59) */
       int tm_hour;   /* Hours (0-23) */
       int tm_mday;   /* Day of the month (1-31) */
       int tm_mon;    /* Month (0-11) */
       int tm_year;   /* Year - 1900 */
       int tm_wday;   /* Day of the week (0-6, Sunday = 0) */
       int tm_yday;   /* Day in the year (0-365, 1 Jan = 0) */
       int tm_isdst;  /* Daylight saving time */
举例:
#include <stdio.h>
#include <time.h>
int main(void)
{
        time_t t1;
        struct tm* t2;
        char *t3;
        t1 = time((time_t *) NULL);
        printf("time--:%ld\n",t1);
        t2 = localtime(&t1);
        printf("loacaltime--tm_sec:%d,tm_min:%d\n",t2->tm_sec,t2->tm_min);
        t2 = gmtime(&t1);
        printf("gmtime--tm_sec:%d,tm_min:%d\n",t2->tm_sec,t2->tm_min);
        t3 = ctime(&t1);
        printf("ctime--tm_sec:%s\n",t3);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值