gpt4 book ai didi

php - C 相当于 PHP `date(' YmdHis')`

转载 作者:太空宇宙 更新时间:2023-11-04 05:28:01 26 4
gpt4 key购买 nike

无法在谷歌上找到答案。

对于 PHP date('YmdHis') 输出,在 C 语言中是否有等价物:

20130613153516

谢谢!

最佳答案

您可以在c 中使用strftime 函数来实现相同的功能。

#include <stdio.h>
#include <time.h>

int main()
{
time_t x;
time(&x);
struct tm *tmptr = localtime(&x);
char buf[1000];

strftime(buf, sizeof(buf), "%Y%m%d%I%M%S", tmptr);
printf("%s\n", buf);

return 0;
}

输出如下:

20130613051142 

基于我的本地时间类(class)。

关于php - C 相当于 PHP `date(' YmdHis')`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17085983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com