您的位置:首页 > 其它

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

2007-10-15 11:48 489 查看
有人在群里问的...写来试一试....

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}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: