字符串转换为DATETIME C# [英] Convert String to Datetime C#

查看:162
本文介绍了字符串转换为DATETIME C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串值,它是一个日期时间:20100825161500,我想将其转换为一个系统日期时间。我曾尝试Convert.ToDateTime和DateTime.Parse而这些不工作。

I have a string value which is a datetime : "20100825161500" and I want to convert this to a System Datetime. I have tried Convert.ToDateTime and DateTime.Parse and these do not work.

推荐答案

您可以使用 DateTime.ParseExact 传递你需要的格式。

You can use DateTime.ParseExact to pass the format you need.

下面是一个例子:

VAR分析= DateTime.ParseExact(20100825161500,YYYYMMDDHHMMSS,NULL);

可能的格式值列在 标准日期和时间格式字符串和的自定义日期和时间格式字符串

Possible format values are listed at Standard Date and Time Format Strings and Custom Date and Time Format Strings

这篇关于字符串转换为DATETIME C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆