惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
G
Google Developers Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
F
Full Disclosure
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
C
Cisco Blogs
博客园 - 司徒正美
Project Zero
Project Zero
L
LINUX DO - 热门话题
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
Scott Helme
Scott Helme
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
S
Securelist
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
T
Threatpost
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
The Register - Security
The Register - Security
S
Security Archives - TechRepublic
博客园 - Franky
N
News | PayPal Newsroom
Simon Willison's Weblog
Simon Willison's Weblog
S
SegmentFault 最新的问题
W
WeLiveSecurity
A
Arctic Wolf
B
Blog

博客园 - 偶然微笑

asp.net 登陆 asp.net获取URL和IP地址 - 偶然微笑 ASP.NET获取IP与MAC地址的方法 ASP.NET获取IP的6种方法 - 偶然微笑 - 博客园 MS SQL Server 2005 通用分页存储过程 又快又简单的sql2005分页存储过程 SQL SERVER 2005分页存储过程 C#区别和认识四个判等函数 C#算法(一)选择排序 创建基于ASP.NET的SMTP邮件服务 url传递中文的解决方案总结 C#如何取硬件标志 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie 提取HTML代码中文字的C#函数 Asp.Net输出数据到EXCEL中 把文字变成图片的小程序 ASP.NET URL Rewrite. URL重写 - 偶然微笑 asp.net采集函数(采集、分析、替换、入库) - 偶然微笑 .net 无限级分类
C#中数字日期转中文日期
偶然微笑 · 2008-09-20 · via 博客园 - 偶然微笑

据客户要求,把"2007-11-4"转换为"二〇〇七年十一月四号"using System;
 
using System.Text;
 
using System.Text.RegularExpressions;
 
 
namespace AndyDateConvert
  {
      
class DateConvert
      {
          
private static DateConvert m_DateConvert = null;
 
         
private char[] strChinese;
 
         
private DateConvert()
         {
             strChinese 
= new char[] {
                 
'','','','','','','','','','',''
             };
         }
 
         
public static DateConvert Instance
         {
             
get
             {
                 
if (m_DateConvert == null)
                     m_DateConvert 
= new DateConvert();
                 
return m_DateConvert;
             }
         }
 
         
public string Baodate2Chinese(string strDate)
         {
             StringBuilder result 
= new StringBuilder();
 
             
// 依据正则表达式判断参数是否正确
             Regex theReg = new Regex(@"(d{2}|d{4})(/|-)(d{1,2})(/|-)(d{1,2})");
             
if (theReg.Match(strDate).Length != 0)
             {
                 
// 将数字日期的年月日存到字符数组str中
                 string[] str = null;
                 
if (strDate.Contains("-"))
                 {
                     str 
= strDate.Split('-');
                 }
                 
else if (strDate.Contains("/"))
                 {
                     str 
= strDate.Split('/');
                 }
 
                 
// str[0]中为年,将其各个字符转换为相应的汉字
                 for (int i = 0; i < str[0].Length; i++)
                 {
                     result.Append(strChinese[
int.Parse(str[0][i].ToString())]);
                 }
                 result.Append(
"");
 
                 
// 转换月
                 int month = int.Parse(str[1]);
                 
int MN1 = month / 10;
                 
int MN2 = month % 10;
 
                 
if (MN1 > 1)
                 {
                     result.Append(strChinese[MN1]);
                 }
                 
if (MN1 > 0)
                 {
                     result.Append(strChinese[
10]);
                 }
                 
if (MN2 != 0)
                 {
                     result.Append(strChinese[MN2]);
                 }
                 result.Append(
"");
 
                 
// 转换日
                 int day = int.Parse(str[2]);
                 
int DN1 = day / 10;
                 
int DN2 = day % 10;
 
                 
if (DN1 > 1)
                 {
                     result.Append(strChinese[DN1]);
                 }
                 
if (DN1 > 0)
                 {
                     result.Append(strChinese[
10]);
                 }
                 
if (DN2 != 0)
                 {
                     result.Append(strChinese[DN2]);
                 }
                 result.Append(
"");
             }
             
else
             {
                 
throw new ArgumentException();
             }
 
             
return result.ToString();
        }
static void Main(string[] args)
        {
            Console.WriteLine(DateConvert.Instance.Baodate2Chinese(
"2007-11-4"));
            Console.WriteLine(DateConvert.Instance.Baodate2Chinese(
"07-11-4"));
            Console.WriteLine(DateConvert.Instance.Baodate2Chinese(
"2007/11/4"));
            Console.WriteLine(DateConvert.Instance.Baodate2Chinese(
"07/11/4"));
        }
    }
}