Who is responsible for deleting the facet?

后端 未结 3 1127
[愿得一人]
[愿得一人] 2020-12-28 13:59

I have a function that uses the Boost.DateTime library for generating the current GMT/UTC date and time string (live example).

std::string get_curr_date() {
         


        
3条回答
  •  梦毁少年i
    2020-12-28 14:29

    Not answering your question as others have already done it. But, it's really not required to construct the locale everytime.

    std::string get_curr_date_time() {
        namespace bpt = boost::posix_time;
        namespace bdt = boost::date_time;
        std::ostringstream os;
        auto date = bdt::second_clock::universal_time();
        const static std::locale currlocale (os.getloc(), new bpt::time_facet("%Y%m%d%H%M%S"));
        boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%a, %d %b %Y %H:%M:%S GMT");
    
        os.imbue(currlocale);
        os << date;
        return os.str();
    }
    

提交回复
热议问题