C# 在 asp.net 中使用 MaskedEditExtender 在 TextBox 中显示当前日期时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18566184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display Current Date Time in TextBox using MaskedEditExtender in asp.net
提问by Muntaqim Umatiya
I try to display current DateTime in txtDateTime How to display current datetime or custom date time in the textbox using Maked Edit Extender Ajax tool kit in asp.net
我尝试在 txtDateTime 中显示当前日期时间如何使用 asp.net 中的 Maked Edit Extender Ajax 工具包在文本框中显示当前日期时间或自定义日期时间
<asp:TextBox runat="server" ID="txtDateTime" ValidationGroup="ModalPopup"></asp:TextBox>
<asp:CalendarExtender runat="server"
TargetControlID="txtDateTime"
PopupPosition="TopRight"
Format="dd/MM/yyyy HH:mm">
</asp:CalendarExtender>
<asp:MaskedEditExtender runat="server"
ID="meeDateTime"
TargetControlID="txtDateTime"
Mask="99/99/9999 99:99"
MaskType="DateTime"
UserDateFormat= "DayMonthYear"
UserTimeFormat="TwentyFourHour"
CultureDateFormat="DMY"
CultureDatePlaceholder="/" CultureTimePlaceholder=":">
</asp:MaskedEditExtender>
protected void Page_Load(object sender, EventArgs e)
{
//txtDateTime.Text = DateTime.Now.ToString("dd/MM/yyyy H:mm);
//txtDateTime.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm);
txtDateTime.Text = DateTime.Now.ToString();
}
code Behind
背后的代码
回答by C Sharper
You dont have to write code in txtDateTime.Text
since you are using ajax control.
txtDateTime.Text
由于您使用的是 ajax 控件,因此您不必编写代码。
You have set TargetControlID="txtDateTime"
so it will automaticali take the date in that text box.
您已经设置TargetControlID="txtDateTime"
好它会自动获取该文本框中的日期。
If you want to take it in masked Edit extender, then:
如果您想在蒙版编辑扩展器中使用它,则:
txtDateTime.Text = String.Format("{0:t}", Now);
Depending on format you want to set date, you can edit String.Format.
根据您要设置日期的格式,您可以编辑 String.Format。