How to initialize a DateTime field?

前端 未结 9 1238
Happy的楠姐
Happy的楠姐 2020-12-06 04:01

I am absolutly new in C# (I came from Java) and I have a very stupid problem

I have to initialize some DateTime fields into an object but I have som

9条回答
  •  借酒劲吻你
    2020-12-06 04:43

    You can either parse a string, like yours. Or you can instansiate a DateTime object with numbers.

    DateTime date1 = new DateTime(1998, 04, 30);
    DateTime date2 = DateTime.ParseExact("1998,04,30", "yyyy,MM,dd", CultureInfo.InvariantCulture);
    

提交回复
热议问题