将GMT日期字符串转换为CTime或COLEDatetime

时间:2011-06-01 09:53:26

标签: c++ mfc

如何将GMT日期字符串转换为CTime或COLEDatetime

“2011/06/01 3:20:20 GMT + 5:30”

2 个答案:

答案 0 :(得分:0)

#include <iostream>
#include <ctime>

using namespace std;

int main( )
{
   // current date/time based on current system
   time_t now = time(0);

   // convert now to string form
   char* dt = ctime(&now);

   cout << "The local date and time is: " << dt << endl;

   // convert now to tm struct for UTC
   tm *gmtm = gmtime(&now);
   dt = asctime(gmtm);
   cout << "The UTC date and time is:"<< dt << endl;
}

答案 1 :(得分:0)

COleDateTime::ParseDateTime

  

lpszDate参数可以采用多种格式。例如,以下字符串包含可接受的日期/时间格式:

"25 January 1996"
"8:30:00"
"20:30:00"
"January 25, 1996 8:30:00"
"8:30:00 Jan. 25, 1996"
"1/25/1996 8:30:00"  // always specify the full year,
                     // even in a 'short date' format