急呀日期怎么加天数呀?如DateTime.Now()加上5,或其他小数之类

chenyongxm 2004-03-17 03:09:18
急呀日期怎么加天数呀?如DateTime.Now()加上5,或其他小数之类
...全文
610 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
terryxin 2004-03-18
  • 打赏
  • 举报
回复
很多了,学习
Lovest 2004-03-18
  • 打赏
  • 举报
回复
AddHours
tongcheng 2004-03-18
  • 打赏
  • 举报
回复
AddHours(8)
chenyongxm 2004-03-18
  • 打赏
  • 举报
回复
是啊,就是转换时区
marvelstack 2004-03-18
  • 打赏
  • 举报
回复
//楼主这个功能更强
TimeSpan ts = new TimeSpan(days,hours,minutes,seconds,millisecondes);
DateTime dt = DateTime.Now.Add(ts);
Lovest 2004-03-17
  • 打赏
  • 举报
回复
AddDays
lonelyegg 2004-03-17
  • 打赏
  • 举报
回复
你的意思是转换时区吧?
acewang 2004-03-17
  • 打赏
  • 举报
回复
看看你自己问题的题目
chenyongxm 2004-03-17
  • 打赏
  • 举报
回复
就是整个日期时间加上二十四分之八
chenyongxm 2004-03-17
  • 打赏
  • 举报
回复
就是整个日期加上二十四分之八
cshadow 2004-03-17
  • 打赏
  • 举报
回复
((DateTime)ds.Tables[0].Rows[i]["日期"]).AddHours(8)
zxkid 2004-03-17
  • 打赏
  • 举报
回复
是不是加上8个小时呢?
((DateTime)ds.Tables[0].Rows[i]["日期"]).AddHours(8)
csxtu 2004-03-17
  • 打赏
  • 举报
回复
8/24是什么意思呢?
chenyongxm 2004-03-17
  • 打赏
  • 举报
回复
以上方法都不行啊
我只想这样
ds.Tables[0].Rows[i]["日期"]这个字段值都加上(8/24)就可以了
zhaolee 2004-03-17
  • 打赏
  • 举报
回复
Let's look at an example of code that doesn't work in the Pacific Time zone in the United States:

Dim d As DateTime
d = DateTime.Parse("Oct 26, 2003 12:00:00 AM") 'date assignment
d = d.AddHours(3.0)
' - displays 10/26/2003 03:00:00 AM – an ERROR!
MsgBox(d.ToString)

The result that is displayed from this calculation may seem correct on first glance; however, on October 26, 2003, one minute after 1:59 AM PST, the daylight savings time change took effect. The correct answer should have been 10/26/2003, 02:00:00 AM, so this calculation based on a local time value failed to yield the correct result. But if we look back at Rule #3, we seem to have a contradiction, but we don't. Let's just call it a special case for using the Add/Subtract methods in time zones that celebrate daylight savings time.

Best Practice #3
When coding, be careful if you need to perform DateTime calculations (add/subtract) on values representing time zones that practice daylight savings time. Unexpected calculation errors can result. Instead, convert the local time value to universal time, perform the calculation, and convert back to achieve maximum accuracy.
Fixing this broken code is straightforward:

Dim d As DateTime
d = DateTime.Parse("Oct 26, 2003 12:00:00 AM") 'date assignment
d = d.ToUniversalTime().AddHours(3.0).ToLocalTime()
' - displays 10/26/2003 02:00:00 AM – Correct!
MsgBox(d.ToString)

The easiest way to reliably add spans of time is to convert local-time-based values to universal time, perform the calculations, and then convert the values back.

xhjdxx1 2004-03-17
  • 打赏
  • 举报
回复
把日期变量转换一下:
用System.convert.todatetime();
xhjdxx1 2004-03-17
  • 打赏
  • 举报
回复
如上所示,其中有addday,addmonth,等,你用.然后有许多函数
DateTime 值类型表示值范围在 C.E.(基督纪元)0001 年 1 月 1 日午夜 12:00:00 到 C.E. 9999 年 12 月 31 日晚上 11:59:59 之间的日期和时间。

时间值以 100 毫微秒为单位(该单位称为刻度)进行计量,而特定日期是自 GregorianCalendar 日历中 C.E. 1 年 1 月 1 日午夜 12:00 以来的刻度数。例如,刻度值 31241376000000000L 表示 0100 年 1 月 1 日(星期五)午夜 12:00:00。DateTime 值始终在显式或默认日历的上下文中表示。

DateTime 值类型与 TimeSpan 值类型的差异在于 DateTime 表示时间上的一刻,而 TimeSpan 表示时间间隔。例如,这表示您可以从 DateTime 的一个实例减去另一个实例来获得它们之间的时间间隔。也可以将正的 TimeSpan 加到当前的 DateTime 来计算将来的日期。

时间值可以加到 DateTime 的实例上,也可以从其中减去。时间值可以为正数也可以为负数,并可以刻度、秒等单位或 TimeSpan 的实例来表示。此值类型中的方法和属性会考虑闰年和月中天数等细节。

此类型中时间值的说明通常使用协调通用时间 (UTC) 标准来表示,该标准以前称为格林尼治标准时间 (GMT)。

DateTime 实例的计算和比较仅当这些实例是在同一时区中创建时才有意义。因此,假定开发人员具有一些外部机制(如显式变量或策略)以了解 DateTime 是在哪个时区创建的。此类中的方法和属性在进行计算和比较时始终使用本地时区。

对 DateTime 的实例进行的计算(如 Add 或 Subtract)不会修改该实例的值。相反,计算会返回 DateTime 的新实例,其值为计算结果。

此类型从 IComparable、IFormattable 和 IConvertible 继承。使用 Convert 类进行转换,而不是使用此类型的 IConvertible 显式接口成员实现。

chenyongxm 2004-03-17
  • 打赏
  • 举报
回复
我是一个日期型的变量加上8/24这样
showtimenow 2004-03-17
  • 打赏
  • 举报
回复
System.DateTime dt = new System.DateTime
dt = DateTime.Now.AddDay(5);
acewang 2004-03-17
  • 打赏
  • 举报
回复
System.DateTime.Now.AddDays(5)
加载更多回复(1)

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧