从字符串转换为日期时间C#问问题投票 [英] Convert from string to date time C# ask question up vote
本文介绍了从字符串转换为日期时间C#问问题投票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am fetching some data from some API, the date am getting is as below: {dd/MM/yyyy hh:mm:ss} "6/15/2014 6:45:00"
Is there anyway I can directly convert it to date time ? Please guide.. Thanks in advance.
我的尝试:
What I have tried:
I tried .ToString(""), Convert.ToDateTime() and Parse/ExactPare but nothing work.
推荐答案
尝试:
Try:
string date = "6/15/2014 6:45:00";
DateTime dt;
if (DateTime.TryParseExact(date, "M/d/yyyy h:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
{
Console.WriteLine(dt);
}
这篇关于从字符串转换为日期时间C#问问题投票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文