2017-05-09 51 views
0

我有一個Epoch(Unix)時間的字符串。 需要將它轉換爲當地時間的字符串。 代碼波紋管工作,但給我UTC時間,不是本地。 2017年9月5日21點55分44秒C++ Poco Epoch(Unix)時間轉換爲LocalTime字符串

using Poco::Timestamp; 
using Poco::DateTimeFormatter; 

Timestamp timeStamp; 
timeStamp = Timestamp::fromEpochTime(jrnTime); 
timeFormatted = DateTimeFormatter::format(timeStamp, "%d-%m-%Y %H:%M:%S"); 

回答

0

不需要使用波科用於此目的。

#include <ctime> 
using std::time_t; 
using std::wstring; 
using std::string; 

string TimeStamp(time_t rawtime) { 
    char buffer[80]; 
    struct tm timeinfo; 
    localtime_s(&timeinfo, &rawtime); 
    strftime(buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%S", &timeinfo); 
    return string(buffer); 
} 

wstring TimeStampW(time_t rawtime) { 
    wchar_t buffer[80]; 
    struct tm timeinfo; 
    localtime_s(&timeinfo, &rawtime); 
    wcsftime(buffer, sizeof(buffer), L"%d-%m-%Y %H:%M:%S", &timeinfo); 
    return wstring(buffer); 
} 
相關問題