十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如果出生日期输入格式为19861212这种格式的话,以1-3月为春季,4-6月为夏季,7-9月为秋季,10-12月为冬季,用以下代码:
目前累计服务客户1000多家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站制作、成都做网站、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联建站始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。
Private Sub Form_Load()
Dim birth As String
Dim year As Integer
Dim month As Integer
Dim day As String
Dim old As Integer
Dim season As String
Dim sx As Integer
Dim fx As String
birth = Trim(Str(InputBox("请输入您的生日,格式为19741212")))
year = Val(Left(birth, 4))
month = Val(Mid(birth, 5, 2))
day = Right(birth, 2)
old = 2015 - year
Select Case month
Case Is = 3
season = "春季"
Case Is = 6
season = "夏季"
Case Is = 9
season = "秋季"
Case Is = 12
season = "冬季"
End Select
sx = (year - 2016) Mod 12
If sx 0 Then
sx = sx + 12
End If
Select Case sx
Case 0
fx = "猴"
Case 1
fx = "鸡"
Case 2
fx = "狗"
Case 3
fx = "猪"
Case 4
fx = "鼠"
Case 5
fx = "牛"
Case 6
fx = "虎"
Case 7
fx = "兔"
Case 8
fx = "龙"
Case 9
fx = "蛇"
Case 10
fx = "马"
Case 11
fx = "羊"
End Select
MsgBox "您的年龄为:" old vbCrLf "您的出生季节为:" season vbCrLf "您的属相为:" fx
End Sub
我也就是闲着无聊,给这5分都不够敲键盘的
Function age(ByVal till As Date, ByVal birth As Date) As String
'计算年龄,几岁几个月几天,till:截止日期,birth生日
Dim year As Integer = 0 '年
year = till.Year - birth.Year
If year 0 Then
Return ""
End If
If year = 0 Then
''
End If
If year 0 Then
If till.Month birth.Month Then
'还差一个月才到一年
year = year - 1
ElseIf till.Month birth.Month Then
'超过一个月
ElseIf till.Month = birth.Month Then
'同一个月
If till.Day birth.Day Then
'从天数看还没到一个月,不操作
year = year - 1
ElseIf till.Day = birth.Day Then
'到了天数,或超了天数
End If
End If
End If
Dim month As Integer = till.Month - birth.Month
If month 0 Then
month = 12 + month
If till.Day birth.Day Then
'从天数看还没到一个月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天数,或超了天数,不操作
End If
ElseIf month = 0 Then
''同一个月
If till.Day birth.Day Then
'从天数看,已经超过了今天的日期,而且肯定不是同一年
month = 11
ElseIf till.Day = birth.Day Then
'到了天数,或超了天数,同一个月,还没过生日
End If
ElseIf month 0 Then
If till.Day birth.Day Then
'从天数看还没到一个月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天数,或超了天数,不操作
End If
End If
Dim day As Integer = till.Day - birth.Day
If day = 0 Then
'ok
ElseIf day 0 Then
day = Date.DaysInMonth(birth.Year, birth.Month) - birth.Day + till.Day
End If
Return year "岁" month "月" day "天"
End Function
dim s as string,y as string i as long
s=xxxxxx19920315xxxx
y=mid(s,7,4)
从身份证的第七位取4个
i=year(now())-val(y)+1
now()函数是获得现在的电脑的时间,year是把now的年份取出,val是把字符串转换成数字,因为刚生下来就是1岁所以要加1
msgbox i
Private Sub Command1_Click()
If IsDate(Text1) = False Then
MsgBox "输入时间错误!"
Exit Sub
End If
Text2 = Round(DateDiff("m", Text1, Now) / 12, 1) "岁"
End Sub
Public Class 主窗体
Dim 身份证号码 As String
Dim 生日年份 As String
Dim 生日月份 As String
Dim 生日日期 As String
Dim 生日 As Date
Private Sub 输出生日按钮_Click(sender As Object, e As EventArgs) Handles 输出生日按钮.Click
Try
If 身份证号码输入框.TextLength = 15 Then
身份证号码 = 身份证号码输入框.Text
生日年份 = "19" 身份证号码.Substring(6, 2)
生日月份 = 身份证号码.Substring(8, 2)
生日日期 = 身份证号码.Substring(10, 2)
ElseIf 身份证号码输入框.TextLength = 18
身份证号码 = 身份证号码输入框.Text
生日年份 = 身份证号码.Substring(6, 4)
生日月份 = 身份证号码.Substring(10, 2)
生日日期 = 身份证号码.Substring(12, 2)
Else
MsgBox("请输入正确的身份证号码!", MsgBoxStyle.Information, "身份证号码有误")
身份证号码输入框.SelectAll()
身份证号码输入框.Focus()
Exit Sub
End If
If IsNumeric(生日年份) And IsNumeric(生日月份) And IsNumeric(生日日期) Then
生日 = New Date(生日年份, 生日月份, 生日日期)
End If
生日标签.Text = 生日.ToLongDateString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
这是 .NET 的,有疑问请追问