时间格式互换 DateTime.ToString("yyyyMMddHHmmss")

有人在群里问的...写来试一试....
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4
 5namespace xiao
 6{
 7    /// <summary>
 8    /// Create by 黄林峰
 9    /// </summary>

10    class Program
11    {
12        static void Main(string[] args)
13        {
14            try
15            {
16                DateTime d;
17                DateTime dNow;
18                dNow = System.DateTime.Now;
19                string strDateTime = dNow.ToString("yyyyMMddHHmmss");
20                Console.WriteLine("当前时间(正常显示):" + dNow.ToString("yyyy年MM月dd日HH时mm分ss秒"));
21                Console.WriteLine("当前时间:"+strDateTime);
22                d = DateTime.ParseExact(strDateTime, "yyyyMMddhhmmss", System.Globalization.CultureInfo.CurrentCulture);  
23                Console.WriteLine("转换时间(正常显示):"+d.ToString("yyyy年MM月dd日HH时mm分ss秒"));
24                Console.WriteLine("转换时间:" + d.ToString("yyyyMMddHHmmss"));
25            }

26            catch (Exception exp)
27            {
28                System.Console.WriteLine(exp.Message);
29            }

30        }

31    }

32}
posted @ 2007-10-15 11:48  何随风  阅读(12719)  评论(2编辑  收藏  举报
@ilovexiao