Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C+中以字符串形式获取unix时间戳+; 我使用函数Time~()来获得C++中的时间戳,但是,在这样做之后,我需要将它转换成字符串。我不能使用ctime,因为我需要时间戳本身(10个字符的格式)。问题是,我不知道时间变量的形式是什么,所以我不知道我在转换它。不能处理它,所以它必须是一个字符串的一些描述,但我不知道什么_C++_Timestamp - Fatal编程技术网

在C+中以字符串形式获取unix时间戳+; 我使用函数Time~()来获得C++中的时间戳,但是,在这样做之后,我需要将它转换成字符串。我不能使用ctime,因为我需要时间戳本身(10个字符的格式)。问题是,我不知道时间变量的形式是什么,所以我不知道我在转换它。不能处理它,所以它必须是一个字符串的一些描述,但我不知道什么

在C+中以字符串形式获取unix时间戳+; 我使用函数Time~()来获得C++中的时间戳,但是,在这样做之后,我需要将它转换成字符串。我不能使用ctime,因为我需要时间戳本身(10个字符的格式)。问题是,我不知道时间变量的形式是什么,所以我不知道我在转换它。不能处理它,所以它必须是一个字符串的一些描述,但我不知道什么,c++,timestamp,C++,Timestamp,如果有人能帮我的话,我将不胜感激,我完全被难住了 或者,您可以将ctime的输出提供给MySQL日期时间字段,并对其进行正确解释吗?为了理解起见,我仍然希望能回答我问题的第一部分,但这会解决我的问题。 最后,时间仅仅是一个整数。 最后,时间仅仅是一个整数。试试sprintf(字符串变量,“%d”,time)或者std::string(itoa(time))?试试sprintf(字符串变量,“%d”,time)或者std::string(itoa(time))时间是一种整数。如果cout以您想要的

如果有人能帮我的话,我将不胜感激,我完全被难住了

或者,您可以将ctime的输出提供给MySQL日期时间字段,并对其进行正确解释吗?为了理解起见,我仍然希望能回答我问题的第一部分,但这会解决我的问题。

最后,时间仅仅是一个整数。


最后,时间仅仅是一个整数。

试试
sprintf(字符串变量,“%d”,time)
或者
std::string(itoa(time))

试试
sprintf(字符串变量,“%d”,time)
或者
std::string(itoa(time))
时间是一种整数。如果
cout
以您想要的方式处理它,您可以使用将其转换为字符串:

std::string timestr(time_t t) {
   std::stringstream strm;
   strm << t;
   return strm.str();
}
std::string timestr(时间){
std::stringstream strm;

strm
time\u t
是某种整数。如果
cout
以您想要的方式处理它,您可以使用将其转换为字符串:

std::string timestr(time_t t) {
   std::stringstream strm;
   strm << t;
   return strm.str();
}
std::string timestr(时间){
std::stringstream strm;

strm我遇到了同样的问题,我解决了它如下:

char arcString [32];
std::string strTmp;

// add start-date/start-time
if (strftime (&(arcString [0]), 20, "%Y-%m-%d_%H-%M-%S", (const tm*) (gmtime ((const time_t*) &(sMeasDocName.sStartTime)))) != 0)
{
    strTmp = (char*) &(arcString [0]);
}
else
{
    strTmp = "1970-01-01_00:00:00";
}

我也有同样的问题,我解决了它如下:

char arcString [32];
std::string strTmp;

// add start-date/start-time
if (strftime (&(arcString [0]), 20, "%Y-%m-%d_%H-%M-%S", (const tm*) (gmtime ((const time_t*) &(sMeasDocName.sStartTime)))) != 0)
{
    strTmp = (char*) &(arcString [0]);
}
else
{
    strTmp = "1970-01-01_00:00:00";
}

这允许打印进程时间戳,但它总是返回134515192。具体地说,我的代码是:char timestamp[10];sprintf(timestamp,“%d”,time);then later query+=timestamp query是std::string。这允许打印进程时间戳,但它总是返回134515192。具体地说,我的代码是:char timestamp[10];sprintf(timestamp,“%d”,time);then later query+=timestamp query是std::string。假设time_t是一个整数在可移植性方面不是一个好主意:“可移植程序不应该直接使用这种类型的值,而是始终依赖于对标准库元素的调用将它们转换为可移植类型。”就可移植性而言,假设time_t是一个整数并不是一个好主意:“可移植程序不应该直接使用这种类型的值,而是始终依赖于对标准库元素的调用来将它们转换为可移植类型。”