DateTime calender in asp.net
The date time displays as 07/10/2011 01:29:20 I want to display only 07/10/2011 01:29 how can I do that.
DateTime now = DateTime.Now.AddHours(12);
txt_ExpiresBy.Text = Convert.ToString(now);
And开发者_StackOverflow社区 I have this datetime calendar which I assign it to a text box, I have to assign this calendar to 3 text box, How can I do it. Should I use three Javascript with different name or can I do with this below?
<script type="text/javascript">
$(function () {
$('.datePicker').datetimepicker();
});
</script>
<asp:TextBox ID="forDatePicker" runat="server" />
txt_ExpiresBy.Text = expirestime.ToString(@"dd/MM/yyyy hh:mm");
The Datetime.ToString() method is pretty flexible or you can use one of the other methods such as ToShortDateString()
.
See the MSDN docs for more details: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
Using the class name to assign the datetimepicker
to multiple textboxes should work just fine.
Use DateTime.ToString() method.
DateTime expirestime = expirestime.AddHours(12);
txt_ExpiresBy.Text = expirestime.ToString();
with overload ToString Method
this.txt_ExpiresBy.Text = DateTime.Now.ToString("dd/mm/yyyy" + " " + "hh:mm");
Regards
精彩评论