如何编写一个人活了多少天的程序

时间:2015-03-25 11:46:17

标签: vb.net

根据用户的出生日期,我必须在visual basic中创建一个函数,以了解该人活了多少天。

TextWindow.WriteLine("Please enter the year of your birth (yyyy):")
yearBirthday = TextWindow.ReadNumber()
TextWindow.WriteLine("Please enter the month of your birth (01-12):")
monthBirthday = TextWindow.ReadNumber()
TextWindow.WriteLine("Please enter the day of your birth (01-31):")
dayBirthday = TextWindow.ReadNumber()

1 个答案:

答案 0 :(得分:0)

DateDiff函数的工作方式如下:

Dim days = DateDiff("d", "1943-01-02", Now)

或者,您也可以使用重载" - "生成TimeSpan对象的运算符:

Dim days = (Now - Date.Parse("1943-01-02")).Days

或者,您可以使用其中一个日期构造函数:

Dim days = (Now - New Date(1943, 1, 2)).Days