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

结果:

  1. {// ::}
  2. Date: {// ::}
  3. Day:
  4. DayOfWeek: Tuesday
  5. DayOfYear:
  6. Hour:
  7. Kind: Unspecified
  8. Millisecond:
  9. Minute:
  10. Month:
  11. Second:
  12. Ticks:
  13. TimeOfDay: {::}
  14. Year:

1

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

结果:

  1. {// ::}
  2. Date: {// ::}
  3. Day:
  4. DayOfWeek: Tuesday
  5. DayOfYear:
  6. Hour:
  7. Kind: Unspecified
  8. Millisecond:
  9. Minute:
  10. Month:
  11. Second:

补充:

如果这么写:

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

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

因为:

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

  1. 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. 关于git SSH Key的 生成

    最近刚接触git,简直就是一小白用户,所以决定自己记录一些东西,以备不时之需 系统环境:Windows 1.首先下载git,http://git-scm.com/download/ 2.正常安装git ...

  2. struts2 CVE-2010-1870 S2-005 XWork ParameterInterceptors bypass allows remote command execution

    catalog . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch Fix 1 ...

  3. Andirod——网络连接(HttpURLConnection)

    Android中使用HTTP协议访问网络的方法主要分为两种: 使用HttpURLConnection 使用HttpClient 本文主要内容是HttpURLConnection的使用. HttpURL ...

  4. Newton-Raphson算法简介及其R实现

    本文简要介绍了Newton-Raphson方法及其R语言实现并给出几道练习题供参考使用. 下载PDF格式文档(Academia.edu) Newton-Raphson Method Let $f(x) ...

  5. HDU 4768 Flyer(二分)

    题目链接: 传送门 Flyer Time Limit: 1000MS     Memory Limit: 32768 K Description The new semester begins! Di ...

  6. 【Beta版本】冲刺-Day2

    队伍:606notconnected 会议时间:12月10日 目录 一.行与思 二.站立式会议图片 三.燃尽图 四.代码Check-in 一.行与思 张斯巍(433) 今日进展:对登录界面做了相应的修 ...

  7. WPF资源字典

    如果相同的资源可用于不同的应用程序,把资源放在一个资源字典中就比较有效. 新建一个资源字典文件Dictionary1.xaml <ResourceDictionary xmlns="h ...

  8. hdu 2037 - 今年暑假不AC(区间调度问题)

    题意:区间调度问题 解法:应用贪心算法,贪心的规则: 在可选的节目中,选取结束时间早的节目. 1: #include<stdlib.h> 2: #include<string.h&g ...

  9. 【Beta】第三次任务发布

    后端(补做) #86 了解社区新建文章.添加评论(回复)的机制.整理成API文档,包括如何请求新建文章.新建评论(回复).如何获取文章内容和评论内容. 验收条件:文档PM要能看懂. 前端(补做) #8 ...

  10. Linux下,使用Git管理 dotfiles(配置文件)

    1.管理你的 dotfiles 作为一个计算机深度使用者,并且长期使用 Linux 作为主要操作系统,折腾各种功能强大的软件是常有的事儿.这些软件有它们各自的配置文件,通常以 . 开头,因此有人管它们 ...