Add the current time to a DateTime?

浪尽此生 提交于 2019-12-04 11:47:12
 string s = "27.08.2010";
 DateTime dt = DateTime.ParseExact(s, "dd.MM.yyyy", CultureInfo.InvariantCulture);
 DateTime result = dt.Add(DateTime.Now.TimeOfDay);

You can parse the string into a DateTime instance then just add DateTime.Now.TimeOfDay to that DateTime instance.

  DateTime date = DateTime.ParseExact("27.08.2010", "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
  TimeSpan time = DateTime.Now.TimeOfDay;
  DateTime datetime = date + time;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!