我想在函数中以字符串格式从时间戳返回 time_t 值,但我不明白。我需要帮助。
我读取了一个 Redis 数据库的字符串 KEY,它是一个时间戳值,格式为,例如“1456242904.226683”
我的代码是:
time_t get_ts(redisContext *ctx)
{
redisReply *reply;
reply = redisCommand(ctx, "GET %s", "KEY");
if(reply == NULL){
return -1;
}
char error[255];
sprintf(error, "%s", "get_ts 2:",reply->str);
send_log(error);
freeReplyObject(reply);
return reply->str;
}
reply->str 是一个字符串值,但我需要返回一个 time_t 值。
我该怎么做?
谢谢