DateTime Conversion and Parsing DateTime.Now.ToString(“MM/dd/yyyy hh:mm:ss.fff”)

前端 未结 3 905
半阙折子戏
半阙折子戏 2020-12-21 07:41

I store some DateTime in a CSV log with:

DateTime.Now.ToString(\"MM/dd/yyyy hh:mm:ss.fff\")

When I try to read it I found something like:

3条回答
  •  粉色の甜心
    2020-12-21 08:21

    use DateTime.ParseExact with specifying the format

    String dateStr=DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff");
    DateTime date = DateTime.ParseExact(dateStr,"MM/dd/yyyy hh:mm:ss.fff",System.Globalization.CultureInfo.InvariantCulture);
    

提交回复
热议问题