'计算两个日期之间相差的天数,并为该天数构造一个 TimeSpan 值
Dim oldDate As Date = $dateLiteral$
Dim newDate As Date = $dateLiteral2$
Dim differenceInDays As Long = DateDiff(DateInterval.Day, oldDate, newDate)
Dim spanFromDays As TimeSpan = New TimeSpan(CInt(differenceInDays), 0, 0, 0)
'计算同一天中两个时间之间相差的秒数,并为该秒数构造一个 TimeSpan 值
Dim oldTime As Date = $timeValue$
Dim newTime As Date = $timeValue2$
' You can also determine the difference in times in other units.
Dim differenceInSeconds As Long = DateDiff(DateInterval.Second, oldTime, newTime)
Dim spanFromSeconds As TimeSpan = New TimeSpan(0, 0, CInt(differenceInSeconds))
'计算指定角度的余弦值(将角度转换成弧度,然后计算余弦值)
Dim radians As Double = $Degrees$ * Math.PI / 180
Dim cos As Double = Math.Cos(radians)
'计算指定角度的正切值
Dim radians As Double = $Degrees$ * Math.PI / 180
Dim tan As Double = Math.Tan(radians)
'计算指定角度的正弦值
Dim radians As Double = $Degrees$ * Math.PI / 180
Dim sin As Double = Math.Sin(radians)
'判断是否是素数
Function X(ByVal val As Integer) As Boolean
Dim flag As Boolean
Dim n, k, i, swit As Integer
n = val
k = Int(Math.Sqrt(n))
i = 2
swit = 0
While i <= k And swit = 0
If n Mod i = 0 Then
swit = 1
Else : i += 1
End If
End While
If swit = 0 Then
flag = True '是素数
Else
flag = False
End If
Return flag
End Function
’身份证判断年龄
Function Sfz(ByVal A As String, ByVal B As String) '判断年龄的过程
If A.Length = 18 Then
A = A.Substring(6, 4) & "-" & A.Substring(10, 2) & "-" & A.Substring(12, 2)
B = DateDiff("yyyy", CDate(A), Now.Date)
ElseIf A.Length = 15 Then
A = "19" & A.Substring(6, 2) & "-" & A.Substring(8, 2) & "-" & A.Substring(10, 2)
B = DateDiff("yyyy", CDate(A), Now.Date)
ElseIf A.Length = 0 Then
MsgBox("身份证号码不能为空,请填写。", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
B = Nothing
Else
MsgBox("该身份证不符合要求")
End If
Return B
End Function