How to set DateTime to null

前端 未结 6 1173
半阙折子戏
半阙折子戏 2021-01-31 13:25

Using C#. I have a string dateTimeEnd.

If the string is in right format, I wish to generate a DateTime and assign it to eventCustom.DateTimeEnd

6条回答
  •  情话喂你
    2021-01-31 14:23

    This should work:

    if (!string.IsNullOrWhiteSpace(dateTimeEnd))
        eventCustom.DateTimeEnd = DateTime.Parse(dateTimeEnd);
    else
        eventCustom.DateTimeEnd = null;
    

    Note that this will throw an exception if the string is not in the correct format.

提交回复
热议问题