vb.net vb.net中的日期时间格式转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6883324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:38:09  来源:igfitidea点击:

Date time format convert in vb.net

vb.netdatetime

提问by Akhil K Nambiar

I'm getting date-time from a source as 20110731183330. I want to convert it to '7/31/2011 06:33:30 PM'. Is there a one line code for the same in vb.net?

我从来源获取日期时间为 20110731183330。我想将其转换为“7/31/2011 06:33:30 PM”。在 vb.net 中是否有相同的一行代码?

采纳答案by Akhil K Nambiar

Dim result As Date = Date.ParseExact(dt, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture)

then we can format it as required.

然后我们可以根据需要对其进行格式化。

回答by drf

That would be:

那将是:

Dim result As Date = Date.ParseExact(datestring, "yyyyMMddHHmmss")

回答by Wahid4sap

It can be...

有可能...

Dim CustomDate As Date = Date.ParseExact(yourdate, "MM/dd/yyyy hh:mm:ss tt", Globalization.DateTimeStyles.None)