简体   繁体   English

asp.net中的DateTime日历

[英]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. 日期时间显示为07/10/2011 01:29:20我想仅显示07/10/2011 01:29我该怎么做。

     DateTime now = DateTime.Now.AddHours(12);
        txt_ExpiresBy.Text = Convert.ToString(now);

And 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. 我有这个日期时间日历,我将其分配给文本框,我必须将此日历分配给3个文本框,我该怎么做。 Should I use three Javascript with different name or can I do with this below? 我应该使用三个不同名称的Javascript,还是可以使用以下内容?

<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() . Datetime.ToString()方法非常灵活,或者您可以使用其他方法之一,如ToShortDateString()

See the MSDN docs for more details: http://msdn.microsoft.com/en-us/library/system.datetime.aspx 有关更多详细信息,请参阅MSDN文档: 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. 使用类名将datetimepicker分配给多个文本框应该可以正常工作。

Use DateTime.ToString() method. 使用DateTime.ToString()方法。

DateTime expirestime = expirestime.AddHours(12);
txt_ExpiresBy.Text = expirestime.ToString();

with overload ToString Method 使用重载ToString方法

this.txt_ExpiresBy.Text = DateTime.Now.ToString("dd/mm/yyyy" + " " + "hh:mm"); this.txt_ExpiresBy.Text = DateTime.Now.ToString(“dd / mm / yyyy”+“”+“hh:mm”);

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM