如何从 VB 中的日期获取这个整数?
txtDate = 3/7/1994
基本上我希望我的按钮计算“月份”数字(在本例中为 7)并将其显示到 txtMonth 中。
最简单的方法是什么?
请注意,日期将来自用户的输入。
顺便说一句,它是针对 Visual Basic 的!如果您能真正解释一下而不是告诉我该怎么做,那就太好了!
找到代码:
Dim theDate As Date
Dim theMonth As Integer
theDate = txtDateOfBirth.Text
theMonth = Month(theDate)
txtMonth.Text = theMonth
干杯!
txtDate = 3/7/1994
Basically I want my button to calculate the 'month' digit (in this case 7) and display it into txtMonth.
What is the simplest way to do this?
Note the date will come from a user's input.
By the way, it's for Visual Basic! If you could actually explain it instead of telling me what to do, that would be great!
Found the code:
Dim theDate As Date
Dim theMonth As Integer
theDate = txtDateOfBirth.Text
theMonth = Month(theDate)
txtMonth.Text = theMonth
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 3/7/1994 用斜杠拆分,从拆分中选择第二个值,然后将其分配给 txtMonth。无论您的编程语言是什么,这都应该是可行的:)
在 C# 中
string[] splits = dateValue.Split("/".ToCharArray());
txtMonth = 分割[1];
假设 dateValue = "3/7/1994"
但请指定您的编程语言。
Split 3/7/1994 it on slashes, pick the second value from the splits and then assign it to txtMonth. This should be doable in whatever your programming language is :)
In C#
string[] splits = dateValue.Split("/".ToCharArray());
txtMonth = splits[1];
Supposing dateValue = "3/7/1994"
But do specify your programming language.
将字符串拆分为一个数组(在“/”上),第二项 (1) 将是您的月份。
Split the string into an array (on "/"), the second item (1), will be your month.
将日期变量转换为日期时间,然后使用日期时间的格式(C# 代码):
convert your date variable to a datetime then use the format of datetime (C# code):