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. 安装Mysql提示1045错误解决方法

    MySQL安装提示一下错误 The security settings could not be applied to the database because the connection has ...

  2. Discuz! X upgrade/converter GETSHELL Vulnerability Via /convert/include/global.func.php Inject Special Symbol Into /convert/data/config.inc.php

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对于PHP应用来说,处于用户的输入并正确划定"数据-代码"边界 ...

  3. Visual Studio 2012环境变量、工作目录、vc++目录、 命令等 的配置和作用

    在调试 Visual Studio 212 程序时,经常有一些动态链接库(即 dll 文件)需要加载到工程里,这样才能依赖第三方库进行程序调试. 这些动态链接库,往往都是测试版本或是开发中的版本,或者 ...

  4. CSS3系列四(Media Queries移动设备样式)

    viewport设置适应移动设备屏幕大小 viewport:允许开发者创建一个虚拟窗口并自定义其窗口的大小或缩放功能 <meta name="viewport" conten ...

  5. 20145212 实验三《敏捷开发与XP实践》

    20145212 实验三<敏捷开发与XP实践> 实验内容 使用git上传代码 与20145223同学一组,使用git相互更改代码 同组实验报告链接:http://www.cnblogs.c ...

  6. time模块

    In [1]: import time In [2]: import datetime In [3]: date_time = datetime.datetime.now() In [4]: prin ...

  7. ecshop 后台模板设置-》设置模板

    ecshop后台“设置模板”出现问题 问题1:不能出现特殊符号  / <!-- TemplateBeginEditable name="5F生活数码/手机" -->&l ...

  8. ecshop添加上传图片

    基础 cls_images.php:  function upload_image(){} $_FILES 输出值:Array ( [group_thumb_url] => Array ( [n ...

  9. swiper 增加同页面增加2个滚动

    js代码 <script type="text/javascript"> var mySwiper = new Swiper('.slide_a',{ noSwipin ...

  10. web前端工程师校园招聘要求

    小燕子对紫薇说:“这辈子也别想着进皇宫了”.可后来她们不但进了宫,还都当上了格格.你在想什么?走呗! 1.去哪了网 前端开发工程师 工作地点:北京 工作职责: 负责去哪儿网各产品线Web前端研发: 负 ...