check if date time string contains time

后端 未结 5 1788
鱼传尺愫
鱼传尺愫 2021-02-06 23:37

I have run into an issue. I\'m obtaining a date time string from the database and and some of these date time strings does not contain time. But as for the new requirement every

5条回答
  •  孤城傲影
    2021-02-07 00:29

    Try this,

    DateTime myDate;
    if (DateTime.TryParseExact(inputString, "dd-MM-yyyy hh:mm:ss", 
        CultureInfo.InvariantCulture, DateTimeStyles.None, out myDate))
    {
        //String has Date and Time
    }
    else
    {
        //String has only Date Portion    
    }
    

    You can try using other format specifiers as listed here, http://msdn.microsoft.com/en-us/library/8kb3ffffd4.aspx

提交回复
热议问题