string time = "";
DateTime.ParseExact(time,"yyyyMMdd",System.Globalization.DateTimeFormatInfo.CurrentInfo);

结果:

{// ::}
Date: {// ::}
Day:
DayOfWeek: Tuesday
DayOfYear:
Hour:
Kind: Unspecified
Millisecond:
Minute:
Month:
Second:
Ticks:
TimeOfDay: {::}
Year:

1

DateTime CreateTime = new DateTime();
如果时间格式:"yyyy-MM-dd HH:mm"
例如:string t="2016-02-02 11:15";
可以:DateTime.TryParse(t,out CreateTime);
也可以:Convert.ToDateTime(t);

结果:

{// ::}
Date: {// ::}
Day:
DayOfWeek: Tuesday
DayOfYear:
Hour:
Kind: Unspecified
Millisecond:
Minute:
Month:
Second:

补充:

如果这么写:

DateTime.ParseExact("","yyyyMMddhhmmss",System.Globalization.DateTimeFormatInfo.CurrentInfo);

是会报错的:Message: "该字符串未被识别为有效的 DateTime。"

因为:

上面的写法只能识别12时计时法;想24时计时法转换的↓

DateTime.ParseExact("","yyyyMMddHHmmss",System.Globalization.DateTimeFormatInfo.CurrentInfo);

hh和HH...........

哈哈

C# DateTime和String转换的更多相关文章

  1. 关于DateTime和String转换的容易犯得错误

    字符串转换成DateTime 在开发中,常常会有DataTime类型和String类型的互相转换的要求,比较常用的写法是var date = Convert.ToDateTime("2012 ...

  2. python 中datetime 和 string 转换

    dt = datetime.datetime.strptime(string_date, fmt) fmt 的格式说明如下: https://docs.python.org/2/library/dat ...

  3. C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

  4. python 时间戳 datetime string 转换

    import datetime import time **datetime转时间戳** In [1]: now = datetime.datetime.now() In [2]: time.mkti ...

  5. python time,string 转换

    1. 将字符串转换成时间,字符串格式为05/16/2015 datetime.datetime.strptime(STRING,"%m/%d/%Y") 2. 将时间转换成字符串:格 ...

  6. ObjectId与DateTime的互相转换

    s会用mongdb中经常会需要用到通过“_id”去检查数据,筛选数据,但是想根据具体时间的id每次都需要做一下转换,这样搜索起来就很简单了. ObjectId转DateTime /// <sum ...

  7. DateTime和字符串转换问题

    DateTime和string之间的相互转换经常碰到,可就这么简单的一个转换其中也有些需要注意的地方. static void Main(string[] args) { string format ...

  8. python学习笔记(datetime、字符串转换)

    datetime对象与字符串可以互相转化 代码如下: from datetime import datetime def datetime_string(time): return time.strf ...

  9. C# DateTime和String(转)

    http://www.cnblogs.com/Pickuper/articles/2058880.html C#语言之“string格式的日期时间字符串转为DateTime类型”的方法 方法一:Con ...

随机推荐

  1. PHP的几个常用加密函数

    在php的开发过程中,常常需要对部分数据(如用户密码)进行加密 一.加密类型: 1.单向散列加密 就是把任意长度的信息进行散列计算,得到固定长度的输出,这个散列计算过程是单向的,即不能对固定长度的输出 ...

  2. Linux Overflow Vulnerability General Hardened Defense Technology、Grsecurity/PaX

    Catalog . Linux attack vector . Grsecurity/PaX . Hardened toolchain . Default addition of the Stack ...

  3. bash 操作 sqlite3

    首先,这是个奇怪的需求...但是遇到了.我参考后文链接里的方法,做了自己的. 表是自己手动建的,数据库名字叫 new.db: create table test (sn varchar(), name ...

  4. class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class

    今天在工作中遇到了下面的问题: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springfram ...

  5. Load Average

    在Linux系统下面,有很多的命令可以查看系统的负载情况:比如top,uptime,w,示例如下: [wenchao.ren@l-cmsweb1.ops.cn1 ~]$ w 18:39:10 up 7 ...

  6. MVC 路由

    1.ASP.NET MVC框架中提供的URL路由机制能够使URL不必映射到应用程序的特定物理文件. 2.当用户访问基于MVC模式创建的网站时,只需要在浏览器地址栏里输入类似于下面的URL: http: ...

  7. RNN 入门教程 Part 3 – 介绍 BPTT 算法和梯度消失问题

    转载 - Recurrent Neural Networks Tutorial, Part 3 – Backpropagation Through Time and Vanishing Gradien ...

  8. win8启动文件夹

    进入C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp.鼠标右键选中粘贴,将软件快捷方式粘贴到启动目录 进入文件夹时路径可能是C: ...

  9. JavaScript学习笔记——BOM_window子对象_History、Location、Screnn对象

    javascript-History.Location.Screnn对象实例讲解 一.history对象 包含浏览器访问过的url 1.属性 length 返回浏览器历史记录的数量 alert(his ...

  10. Bindless Textures

    http://shikihuiku.wordpress.com/2014/02/10/openglのtextureについて/