Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将datetime转换为c#格式的指定格式?_C# - Fatal编程技术网

将datetime转换为c#格式的指定格式?

将datetime转换为c#格式的指定格式?,c#,C#,我想将“yy/MM/dd HH:MM:ss”格式(如17/07/18 06:30:20)转换为c#中的2017年7月18日06:30:20。最好的方法是什么 您可以使用DateTime.ParseExact如下所示: DateTime.ParseExact("17/07/18 06:30:20", "yy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture ).ToString("MMM. dd, yyyy HH:mm:ss"); 选择一个或构建您自己

我想将“yy/MM/dd HH:MM:ss”格式(如17/07/18 06:30:20)转换为c#中的2017年7月18日06:30:20。最好的方法是什么

您可以使用
DateTime.ParseExact
如下所示:

DateTime.ParseExact("17/07/18 06:30:20", "yy/MM/dd HH:mm:ss", 
CultureInfo.InvariantCulture
).ToString("MMM. dd, yyyy HH:mm:ss");

选择一个或构建您自己的:@mxms有一个新的,我认为它是一个更好的-您是从
字符串开始的还是从
日期时间开始的
DateTime
没有格式,当你显示它时,它只会得到一个格式,所以从问题开始就不清楚你是从什么开始的(答案会有所不同)很抱歉标题不好,但是Aman给出的答案对我来说很有用。谢谢大家,做得很好。谢谢