免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4214 | 回复: 7

[函数] 在linux下面怎么找不到cftime函数? [复制链接]

论坛徽章:
0
发表于 2005-12-30 15:37 |显示全部楼层
我已经#include <time.h>
可使用cftime的时候说找不到,怎么办啊?

论坛徽章:
0
发表于 2005-12-30 17:26 |显示全部楼层
man cftime
如果 No manual说明没有
什么功能?找个函数代替

论坛徽章:
0
发表于 2005-12-30 17:53 |显示全部楼层
cftime()函数是做什么的?

论坛徽章:
0
发表于 2005-12-31 09:06 |显示全部楼层
下面是unix下的程序,可是移植到linux下就不好用了,
time_t  ktime;

    time(&ktime);

    cftime( upd_date, (char *)"%Y/%m/%d-%H:%M:%S", &ktime );

论坛徽章:
0
发表于 2005-12-31 09:46 |显示全部楼层
下面这段程序在unix下可以正常编译执行,可在linux下就提示undefined reference to `cftime'
-----------------------------------------------------
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
    char upd_date[64];
    time_t  ktime;

    memset(upd_date, '\0', sizeof(upd_date));

    time(&ktime);

    cftime( upd_date, (char *)"%Y/%m/%d-%H:%M:%S", &ktime );

    printf("%s\n", upd_date);

    return 0;
}

论坛徽章:
0
发表于 2005-12-31 11:10 |显示全部楼层
localtime() + strptime() 应该可以代替

论坛徽章:
0
发表于 2010-12-06 09:55 |显示全部楼层
#include <stdio.h>
#include <string.h>
#include <time.h>

char *cftime(char *s, const char *format, time_t *time)
{
    strftime(s, 256, format, localtime(time));
    return s;
}


int main(void)
{

    struct tm *tm_ptr = NULL;
    time_t the_time;
    char buf[256] = {0};

    time(&the_time);

    cftime(buf, "%Y-%m-%d %T", &the_time);

    printf("%s\n", buf);

    return 0;
}

这样才可以实现,6楼的方法,我试了下,不正确。
strptime是通过时间格式的字符串,转换为struct tm*

论坛徽章:
0
发表于 2010-12-07 16:45 |显示全部楼层
长学问啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP