gpt4 book ai didi

c++ - Unix 时间戳到 XML 日期时间转换

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:50 26 4
gpt4 key购买 nike

是否有可用的 C++ 库 api 将 Unix 时间戳转换为 XML 数据类型日期时间

例如:

http://books.xmlschemata.org/relaxng/ch19-77049.html

我希望转换成模式:2001-10-26T19:32:52+00:00

我也可以访问 mysql,所以我可以得到:

mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2010-09-28 14:47:47 |
+---------------------+

我找不到任何适合这个的格式化函数。

我只是不喜欢为此进行字符串操作,除非没有出路....

干杯!

最佳答案

您可以使用 strftime()来自 <time.h> 的函数:

char time_buf[21];
time_t now;
time(&now);
strftime(time_buf, 21, "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));

关于c++ - Unix 时间戳到 XML 日期时间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3813492/

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