John
John

Reputation: 487

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

Upvotes: 0

Views: 1120

Answers (3)

Geoff Appleford
Geoff Appleford

Reputation: 18832

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.

Upvotes: 1

Carmelo La Monica
Carmelo La Monica

Reputation: 765

with overload ToString Method

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

Regards

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

Use DateTime.ToString() method.

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

Upvotes: 1

Related Questions