COleDateTime在Unicode下,Format函数会有问题。

 楼主发表于:2007-04-19 15:03:24比如:
AfxMessageBox(COleDateTime.Format(_T( "我爱你%Y-%m-%d   %H:%M:%S ")));

在ANSI下,正常,在Unicode下,会有断言错,或是得到一个空的CString!
Unicode下,如果不带中文,也不会有错,比如:
AfxMessageBox(COleDateTime.Format(_T( "123%Y-%m-%d   %H:%M:%S ")));
 
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 回复次数:5 
 
yang79tao
 
(杨狼 www.ST-Curve)

等 级:
 #1楼 得分:0回复于:2007-04-20 11:04:25没人会?
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 精华推荐:ip首部中3bit标志字段“更多片”bit的作用。
 
yxz_lp
 
(平乐无忧)

等 级:
 #2楼 得分:5回复于:2007-04-20 11:20:03COleDateTime   ti;
ti=ti.GetCurrentTime();
CString   str=ti.Format(_T( "123%Y-%m-%d   %H:%M:%S "));
AfxMessageBox(str);
这是我的代码,在UNICODE下没错呀!
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 精华推荐:真的假的,关于c++ 2009新标准
 
waitlife
 


等 级:
 #3楼 得分:25回复于:2007-04-20 11:33:47//   使用本地语言以支持函数输出中文
_tsetlocale(LC_ALL,   _T( "Chinese-simplified "));

在UNICODE中,使用这个函数后,其它不支持中文的函数都可以正常用
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 精华推荐:【求助】文件传输断电续传的问题 100 不够再加 
 
yang79tao
 
(杨狼 www.ST-Curve)

等 级:
 #4楼 得分:0回复于:2007-04-20 17:38:11加上_tsetlocale(LC_ALL,   _T( "Chinese-simplified "));后,如果运行于英文操作系统之下,会不会有问题?
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 精华推荐:请问怎么使一个模块满足下面这些需求?(多进程访问,唯一性,外部回调)
 
waitlife
 


等 级:
 #5楼 得分:0回复于:2007-04-20 23:41:37参见MSDN:
If   a   valid   locale   and   category   are   given,   returns   a   pointer   to   the   string   associated   with   the   specified   locale   and   category.   If   the   locale   or   category   is   invalid,   returns   a   null   pointer   and   the   current   locale   settings   of   the   program   are   not   changed.

For   example,   the   call  

setlocale(   LC_ALL,   "English "   );

sets   all   categories,   returning   only   the   string  

English_United   States.1252

If   all   categories   are   not   explicitly   set   by   a   call   to   setlocale,   the   function   returns   a   string   indicating   the   current   setting   of   each   of   the   categories,   separated   by   semicolons.   If   the   locale   argument   is   a   null   pointer,   setlocale   returns   a   pointer   to   the   string   associated   with   the   category   of   the   program 's   locale;   the   program 's   current   locale   setting   is   not   changed.

The   null   pointer   is   a   special   directive   that   tells   setlocale   to   query   rather   than   set   the   international   environment.   For   example,   the   sequence   of   calls

//   Set   all   categories   and   return   "   English_United   States.1252 "

setlocale(   LC_ALL,   "English "   );

//   Set   only   the   LC_MONETARY   category   and   return   "French_France.1252 "

setlocale(   LC_MONETARY,   "French "   );

setlocale(   LC_ALL,   NULL   ); 
 

原文地址:https://www.cnblogs.com/kevinzhwl/p/3878971.html