當「DateTime.ParseExact」我有一個Nullable DateTime
,我得到了一個錯誤:錯誤使用可空的DateTime
其他信息:字符串未被識別爲有效的DateTime。
我看着here,here,here也here。我也試過String.Format("{0:s}", dateTime)
,但它不會改變我DateTime
format.My代碼就像下面,
if (person.JsonData.PasswordChangeRequestTime != null)
{
DateTime data;
data = DateTime.ParseExact(((DateTime)person.JsonData.PasswordChangeRequestTime).Date.ToStringDateTime(), "dd'-'MM'-'yyyy HH':'mm':'ss", CultureInfo.InvariantCulture);
person.setColumnValue("passwordchangerequesttime", data);
}
我的一個DateTime
的是這樣的: 1/1/2015 2:00:00 PM
我希望他們在 1-1-2015 14:00:00
是什麼格式我的DateTime.ParseExact
函數錯了嗎?
順便說一句,我不希望使用subString
功能!
這是什麼方法 - 「ToStringDateTime()'? –
@ shree.pat18我以爲它可能會將其轉換爲字符串!它不工作'(DATETIME)person.JsonData.PasswordChangeRequestTime).Date.ToString()' –
你開始用'DateTime' - 但它是非常不清楚應該是什麼您的操作的最終結果(看起來像'DateTime'再次)。不會只是'data = person.JsonData.PasswordChangeRequestTime;'工作嗎? –