如何将字符串转换为日期格式(mm / dd / yyyy)? [英] How to convert string to date format (mm/dd/yyyy)?
问题描述
我有字符串日期(25.05.2016),我想在VB.net中将其转换为(mm / dd / yyyy)格式。
请建议解决方案。
我尝试过:
我有字符串日期(25.05.2016),我想在VB.net中将其转换为(mm / dd / yyyy)格式。
请建议解决方案。
I have string date (25.05.2016) ,i want to convert it into (mm/dd/yyyy) format in VB.net.
Please suggest solution.
What I have tried:
I have string date (25.05.2016) ,i want to convert it into (mm/dd/yyyy) format in VB.net.
Please suggest solution.
推荐答案
这里有一些例子,你可以用DateTime做什么,日期时间示例 [ ^ ]。
我想您需要的方法是首先使用DateTime.Parse获取正确的Datetime对象并将其格式化为您想要的结果。
Here you find some examples what you can do with the DateTime, DateTime Examples[^].
I guess the way you need to go is first using DateTime.Parse to get a proper Datetime Object and the format it into your desired result.
它是c#而不是vb.net但它应该是直接阅读和转换。
It's c# and not vb.net but it should be straight-forward to read and convert.
string ds = "25.05.2016";
DateTime dt;
if (DateTime.TryParseExact(ds, "dd.MM.yyyy", System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.None, out dt))
{
ds = dt.ToString("MM/dd/yyyy");
}
但是请注意,日期没有格式,所以没有DateTime类这样的东西对于某种格式,日期只有在将它们转换为字符串时才有格式。
Note, however, that dates don't have a format so there is no such thing as a DateTime class with a certain format, dates only have a format when you convert them to a string.
这篇关于如何将字符串转换为日期格式(mm / dd / yyyy)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!