我正在使用Entity Framework我想添加日期和时间。我从前端获取日期,而不仅仅是连接时间
datetime dt = dtstring//31/Mar/2015
然后添加
time tm = '12:00:00:000'
并在SQL中插入数据后
'2015-03-31 12:00:00:000', '2015-03-31 11:59:59:000'
答案 0 :(得分:2)
string one = "31/Mar/2015";
string two = "12:00:00:000";
DateTime dt1 = DateTime.ParseExact(one + " " + two, "dd/MMM/yyyy h:mm:ss:fff", CultureInfo.InvariantCulture);
Console.WriteLine(dt1.ToString("yyyy-MM-dd h:mm:ss:fff"));
答案 1 :(得分:0)
在C#中
DateTime now = DateTime.Now.Date;
TimeSpan time = new TimeSpan(1, 10, 30); // time to be added
long ticks = time.Ticks;
now = now.AddTicks(ticks);