简体   繁体   English

使用C ++在Android下将const char *转换为struct tm

[英]convert const char * to struct tm under Android with C++

I want to get a struct tm from a const char * . 我想从const char *获取一个struct tm In order to achieve the goal I use following code: 为了实现这一目标,我使用以下代码:

CCLog("ServerTimeStamp:%s",servertimestamp);
struct tm servertime;
servertime.tm_isdst=0;
servertime.tm_gmtoff=0;
CCLog("servertime prev:{%i,%i,%i,%i:%i:%i+%i+%li}",servertime.tm_year,servertime.tm_mon,servertime.tm_mday,servertime.tm_hour,servertime.tm_min,servertime.tm_sec,servertime.tm_isdst,servertime.tm_gmtoff);
strptime(servertimestamp, "%FT%TZ", &servertime);
CCLog("servertime post:{%i,%i,%i,%i:%i:%i+%i+%li}",servertime.tm_year,servertime.tm_mon,servertime.tm_mday,servertime.tm_hour,servertime.tm_min,servertime.tm_sec,servertime.tm_isdst,servertime.tm_gmtoff);

But the output is: 但是输出是:

ServerTimeStamp:2014-07-18T11:51:09Z
servertime prev:{24,1803363120,22,1803363016:0:1796668624+0+0}
servertime post:{24,1803363120,22,1803363016:0:1796668624+0+0}

Which means that strptime has probably done nothing. 这意味着strptime可能什么也没做。 Is this function not implemented on Android under JNI (In the cocos2d-x environment, version 2.1rc0-x-2.1.4)? 在JNI下(在cocos2d-x环境中,版本为2.1rc0-x-2.1.4)在Android上未实现此功能吗? What would be a suitable alternative? 什么是合适的选择? How can I convert the const char * to struct tm ? 如何将const char *转换为struct tm

My App is cross-platform, and the same code works perfectly under iOS (also with the environment cocos2d-x, version 2.1rc0-x-2.1.4). 我的应用程序是跨平台的,并且相同的代码在iOS(在环境cocos2d-x,版本2.1rc0-x-2.1.4)下也能完美运行。

Thanks in advance! 提前致谢!

请勿在日期中使用%F说明符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM