2

我想从 VB 日期对象中减去 18 年。
这是代码示例:

Dim someVar
DirectCast(pcontrol, DateTimePicker).Value = Date.Now.Subtract(someVar)

someVar 值是 ?

4

1 回答 1

8

这看起来很奇怪,但请尝试使用AddYears, 但使用负数:

With DirectCast(pcontrol, DateTimePicker)
  .Value = .Value.AddYears(-18)
End With

或者正如 MarkJ 指出的那样,试图从现在开始减去它:

With DirectCast(pcontrol, DateTimePicker)
  .Value = Now.AddYears(-18)
End With
于 2012-04-25T16:06:37.840 回答