开发者

convert datetime js to c#

开发者 https://www.devze.com 2023-01-11 15:08 出处:网络
How would I convert this from js to C#. I\'ve looked but cant find anything useful. var endDate = new DateTime();

How would I convert this from js to C#. I've looked but cant find anything useful.

var endDate = new DateTime();
endDate.setDate(startDateTime.getDate() + days);
endDate.setHours(endDateTime.getHours(), endD开发者_开发百科ateTime.getMinutes(), endDateTime.getSeconds());


Assuming that you don't mind sub-second precision on endDateTime, you could use:

var endDate = startDateTime.Date.AddDays(days).Add(endDateTime.TimeOfDay);                                               

If you do mind, this should do the trick:

var offSet = new TimeSpan(days, endDateTime.Hour, endDateTime.Minute, endDateTime.Second);
var endDate = startDateTime.Date.Add(offSet);
0

精彩评论

暂无评论...
验证码 换一张
取 消