我想从日期字符串和时间字符串构造一个 ISO 8601 格式的日期。从 SOAP 请求中,我得到字符串中的日期和时间。日期和时间以格林威治标准时间为准。现在,我想构造一个 ISO 8601 格式的日期。
例如,我有日期字符串 = 2012-10-23 和时间字符串 = 21:30:10
我希望使用上述两个细节构造日期时间字符串,例如 2012-10-23T23:30:10.000Z
我怎样才能在 C++ 中做到这一点?请建议。
你可以简单地做:
#include <iostream>
using namespace std;
string MakeISODate( string iDate, string iTime )
{
return iDate + "T" + iTime + "Z";
}
int main()
{
string date = "2012-10-23";
string time = "21:30:10";
string isoDate = MakeISODate( date, time );
cout << "ISO 8601 : " << isoDate << endl;
return 0;
}