简体   繁体   中英

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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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