日期时间拆分需要帮助 [英] Date Time Split Help Required
问题描述
我正在制作一个Web应用程序,其中我的个人资料页面上有出生日期字段(注册后)
该字段有3个下拉菜单,分别是月日和年
Hi,
I am making a web application,in which i have a field of Date of birth on profile page(which is after registration)
The Field have 3 dropdownlists for Month- day- and year
@Html.DropDownList("year", dob)@Html.DropDownList("month", month)@Html.DropDownList("day",day)
where dob,month and day are List object
在数据库中,此列的类型为DateTime,当用户创建配置文件时,它将在其中保存值,但是当用户要编辑此字段时,我该如何使用存储在其中的dateof填充这些下拉列表
对于例如
此字段的默认值为1980年1月1日12:00 AM
如何拆分并在3个下拉列表中显示?
问候
In database this column is of type DateTime, When user create the profile it will save values in it, but when user wants to edit this field then how can i populate these dropdowns with the dateofbirth stored in it
For eg
the default value for this field is Jan 1 1980 12:00 AM
how can i split it and display on 3 dropdowns?
Regards
推荐答案
如果您的日期是一个DateTime,那么它相当容易.
只需提取日,月和年,如下所示.
If you date is a DateTime then its fairly easy.
Just extract the Day, Month and Year as shown below.
int year = dt.Year;
int month = dt.Month;
int day = dt.Day;
然后,您可以将它们直接分配给您的下拉菜单.
在此处 [
You can then assign them directly to your dropdowns.
Read more about this here[^].
这篇关于日期时间拆分需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!