Unix时间戳到XML日期时间转换 [英] Unix timestamp to XML date time conversion

查看:234
本文介绍了Unix时间戳到XML日期时间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何C ++ Library api可用于将Unix时间戳转换为XML数据类型datetime



例如:

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

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



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

  mysql>选择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:%S:%MZ,gmtime(& now));


Is there any C++ Library api available which converts Unix timestamp to XML datatype datetime

eg :

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

I am looking to convert into pattern : 2001-10-26T19:32:52+00:00

I also have access to mysql, so I can get hold of :

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

I could not find any formatting functions which would fit this.

I just don't prefer string manipulation for this , unless there is no way out....

Cheers!

解决方案

You could use the strftime() function from <time.h>:

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

这篇关于Unix时间戳到XML日期时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆