中文日期格式问题

bqljb 2007-02-01 11:46:44
请教各位:如何可以最方便实现显示中文日期格式,如:二00七年一月八日,一定要自己写函数吗?
...全文
342 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
MaybeHelios 2007-02-01
  • 打赏
  • 举报
回复
不知道这个行不
IFormatProvider culture = new CultureInfo("zh-CHS", true);
重典 2007-02-01
  • 打赏
  • 举报
回复
还是自己写个吧,十次replace就行了,不难
glacier111 2007-02-01
  • 打赏
  • 举报
回复
最好不要改系统设置,这样就造成程序不通用,自己写个函数也不麻烦吧
luck200803 2007-02-01
  • 打赏
  • 举报
回复
你可以把系统显示的时间格式改成这个格式,那么输出的时间格式就是这样了.....不用写
bqljb 2007-02-01
  • 打赏
  • 举报
回复
感谢各位回复,首先我试过IFormatProvider culture = new CultureInfo("zh-CHS", true);尽管没效果,但非常感谢MaybeHelios兄弟,这个思路是最好的;看来只有写讨厌的函数了,深谢各位呵呵!
CGACHA 2007-02-01
  • 打赏
  • 举报
回复
//帮你简单写了个 可能不太好 LZ再改改吧
string finalTime="";
string time=System.DateTime.Now.ToString("yyyyMMdd");
for(int i=0;i<time.Length;i++)
{
string convtime=time.Substring(i,1);
finalTime+=ReturnTime(convtime,i);
}


private string ReturnTime(string convtime,int count)
{
string returntime="";
if(convtime=="0"&&count!=4&&count!=6)
{returntime="零";}
else if(convtime=="1")
{returntime="一";}
else if(convtime=="2")
{returntime="二";}
else if(convtime=="3")
{returntime="三";}
else if(convtime=="4")
{returntime="四";}
else if(convtime=="5")
{returntime="五";}
else if(convtime=="6")
{returntime="六";}
else if(convtime=="7")
{returntime="七";}
else if(convtime=="8")
{returntime="八";}
else if(convtime=="9")
{returntime="九";}

if(count==3)
{returntime+="年";}
else if(count==5)
{returntime+="月";}
else if (count==7)
{returntime+="日";}

return returntime;
}

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧