使用 gSOAP 以本地时间而不是 UTC 返回日期时间
returning dateTime in local time instead of UTC with gSOAP
我有一个使用 gSOAP 的 soap 服务器。其中一个请求在响应中包含 xsd:dateTime
字段。此 dateTime
始终 return 为 UTC,但我想 return 为本地时间的 dateTime
。我将本地时间填写为 time_t
,然后将其转换为 xsd:dateTime
,gsoap 会自动将其转换为 UTC。我可以改变这种行为吗?
在 this link it sounds like gsoap will always use UTC ("A time_t
value is considered and represented in UTC by the serializer."). I also already searched through the flags here 中,但我找不到适合我的用例的标志。
看来自己想要拥有的东西并没有那么容易。我假设我需要为 xsd:dateTime
编写自己的自定义序列化程序,类似于 this link.
中的示例
不过,如果有人有更好的解决方案或对如何编写这样的序列化程序有任何建议,请告诉我您的想法。
在执行内部soap_dateTime2s
函数(as found here), it appears to test several config flags (settable in config.h
)。
我没有测试过,但似乎要根据当地时间获得输出,HAVE_GMTIME_R
和 HAVE_GMTIME
需要未定义。
要使用当地时间而不是 gmt 时间,在 ./configure
之后更改 config.h
如下:
/* Define to 1 if you have the `gmtime' function. */
//#define HAVE_GMTIME 1
#undef HAVE_GMTIME
/* Define to 1 if you have the `gmtime_r' function. */
//#define HAVE_GMTIME_R 1
#undef HAVE_GMTIME_R
然后制作 gsoap
,现在 soap_dateTime2s
将 return 本地时间。
喜欢
2017-10-24T02:28:41Z will be return as 2017-10-24T10:28:41+08:00
我有一个使用 gSOAP 的 soap 服务器。其中一个请求在响应中包含 xsd:dateTime
字段。此 dateTime
始终 return 为 UTC,但我想 return 为本地时间的 dateTime
。我将本地时间填写为 time_t
,然后将其转换为 xsd:dateTime
,gsoap 会自动将其转换为 UTC。我可以改变这种行为吗?
在 this link it sounds like gsoap will always use UTC ("A time_t
value is considered and represented in UTC by the serializer."). I also already searched through the flags here 中,但我找不到适合我的用例的标志。
看来自己想要拥有的东西并没有那么容易。我假设我需要为 xsd:dateTime
编写自己的自定义序列化程序,类似于 this link.
不过,如果有人有更好的解决方案或对如何编写这样的序列化程序有任何建议,请告诉我您的想法。
在执行内部soap_dateTime2s
函数(as found here), it appears to test several config flags (settable in config.h
)。
我没有测试过,但似乎要根据当地时间获得输出,HAVE_GMTIME_R
和 HAVE_GMTIME
需要未定义。
要使用当地时间而不是 gmt 时间,在 ./configure
之后更改 config.h
如下:
/* Define to 1 if you have the `gmtime' function. */
//#define HAVE_GMTIME 1
#undef HAVE_GMTIME
/* Define to 1 if you have the `gmtime_r' function. */
//#define HAVE_GMTIME_R 1
#undef HAVE_GMTIME_R
然后制作 gsoap
,现在 soap_dateTime2s
将 return 本地时间。
喜欢
2017-10-24T02:28:41Z will be return as 2017-10-24T10:28:41+08:00