我试图将VB转换为c#,在VB中 DATEADD 在C#中工作会产生错误
DateTime viewPortStartDate = DateAdd("s", viewer.ViewPortLeft * m_dateRange, m_dtmMinDate);
DateTime viewPortEndDate = DateAdd("s", viewer.ViewPortWidth * m_dateRange, viewPortStartDate);
答案 0 :(得分:1)
C#中的Adddays:
viewPortStartDate.AddDays(1);
如果你想要一个范围,你可以使用持续时间:
DateTime today = DateTime.Now;
TimeSpan duration = new TimeSpan(7, 0, 0, 0); //Adding 7 days from date today
DateTime result = today.Add(duration);
要添加小时,分钟和秒,您可以执行以下操作:
today = today.AddDays(1).AddHours(1).AddMinutes(1).AddSeconds(1);
或者仅限于秒:
today = today.AddSeconds(1);