How to format date and time string in C++

后端 未结 6 1305
终归单人心
终归单人心 2020-12-09 09:57

Let\'s say I have time_t and tm structure. I can\'t use Boost but MFC. How can I make it a string like following?

Mon Apr 23 17:48:14 2012

6条回答
  •  情话喂你
    2020-12-09 10:19

    If you need to worry about formatting on different locales, don't forget to initialize the CRT with the current locale. This affects COleDateTime too.

    setlocale(LC_COLLATE,“.OCP”); // sets the sort order
    
    setlocale(LC_MONETARY, “.OCP”); // sets the currency formatting rules
    
    setlocale(LC_NUMERIC, “.OCP”); // sets the formatting of numerals
    
    setlocale(LC_TIME, “.OCP”); // defines the date/time formatting
    

    See my blog post which ties in MSDN articles and other sources. http://gilesey.wordpress.com/2012/12/30/initailizing-mfccrt-for-consumption-of-regional-settings-internationalizationc

提交回复
热议问题