转换stringdate =" YYYYMMDD"到约会时间...... [英] Convert stringdate = "YYYYMMDD" to datetime ...

查看:115
本文介绍了转换stringdate =" YYYYMMDD"到约会时间......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做时,我不能得到约会,因为是incorect格式。我尝试了一切。有人有解决方案吗?



我尝试了什么:



When I do this i cant get date because is incorect format. I try everything. Someone have solution?

What I have tried:

DateTime d;
string dateTimeFormat = "yyyymmdd";
string strdate = "20180521";
d = DateTime.ParseExact(strdate , dateTimeFormat, CultureInfo.CurrentCulture)

推荐答案

日期格式区分大小写



The date formats are case sensitive

string dateTimeFormat = "yyyyMMdd";


除了解决方案#1通过 F-ES Sitecore [ ^ ],我强烈建议您阅读:

标准日期和时间格式字符串| Microsoft Docs [ ^ ]

自定义日期和时间格式字符串| Microsoft Docs [ ^ ]



如MSDN文档所述:

In addition to solution #1 by F-ES Sitecore[^], i'd strongly suggest to read this:
Standard Date and Time Format Strings | Microsoft Docs[^]
Custom Date and Time Format Strings | Microsoft Docs[^]

As MSDN documentation states:
Quote:

m 自定义格式说明符将分钟表示为0到59之间的数字。



M 自定义格式说明符将月份表示为1到12之间的数字(或从1到13表示日历)有13个月的时间。

The "m" custom format specifier represents the minute as a number from 0 through 59.

The "M" custom format specifier represents the month as a number from 1 through 12 (or from 1 through 13 for calendars that have 13 months).





结论:格式区分大小写。



Conclusion: format is case sensitive.


这篇关于转换stringdate =" YYYYMMDD"到约会时间......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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