【问题标题】:How to get Current date using Poco ? (Only Date) No Time Stamp如何使用 Poco 获取当前日期? (仅日期)无时间戳
【发布时间】:2020-09-18 10:03:53
【问题描述】:

有没有办法只从 Poco 获取 Date ?一种方法是获取 Poco DateTime 标记并截断日期,但是有什么方法可以直接给出当前日期? 比如我用这样的方法来获取日期

void getTimestamp(std::string &out_iTimestamp)
{
   //Get the CurrentTimestamp
   Poco::Timestamp t_oCurTimestamp;
   Poco::DateTimeFormatter t_oFormatter;
   string t_strDateTime;
   t_oFormatter.append(t_strDateTime, t_oCurTimestamp, Poco::DateTimeFormat::ISO8601_FORMAT);
   out_iTimestamp = t_strDateTime;

} 现在我正在截断日期

std::string t_strDateTime;
std::string t_strDate;
getTimestamp(t_strDateTime);
//extract the only Date from DateTimeStamp
std::size_t found = t_strDateTime.find('T');
if (found != std::string::npos){
    t_strDate = t_strDateTime.substr(0,found);
}

有人知道简单的方法吗?

【问题讨论】:

    标签: c++11 poco poco-libraries


    【解决方案1】:

    正如已经回答的here,使用您自己的格式的 Poco::DateTimeFormatter:

    Poco::DateTimeFormatter::format(date, "%d/%m/%Y");
    

    【讨论】:

    • 谢谢我也是这样做的
    • @Gaurav,如果对您有帮助,请将其标记为答案。
    猜你喜欢
    • 2010-12-31
    • 2013-03-10
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多