ima
ima

Reputation: 69

Set date time format in asp

One question for this problem, the changes I made seems no effect.

in main file i have as below code:

<tr id="trOrderDate" runat="server">
  <td class="padLOff" style="text-align: left"><b>Order Date:</b></td>
  <td><asp:Textbox ID="lblOrderDate" runat="server" CssClass="form-control" ReadOnly="true" /></td>
</tr>

behind the lblOrderdate id, i have a code as below:

lblOrderDate.Text = order.Summary.OrderDate.ToString("dd/MM/yyyy");

The result will show as below: enter image description here

I have tried to removed the format as below code to show the full data (date and time):

lblOrderDate.Text = order.Summary.OrderDate.ToString();

But the result still show as previous image. I have checked the data in database have include the date time format.

Have any idea on the issue or any way for me to show the date and time.

Thanks

Upvotes: 0

Views: 735

Answers (2)

fhogberg
fhogberg

Reputation: 415

lblOrderDate.Text = order.Summary.OrderDate.ToLongDateString();

DateTime.ToLongDateString() outputs a formatted string with date and time. It will be formatted in whatever culture is set as CultureInfo.CurrentCulture while manually specifying a format as comments and other answer suggested will produce the same result disregarding of CultureInfo.CurrentCulture

Upvotes: 1

M. Schena
M. Schena

Reputation: 2107

simply:

lblOrderDate.Text = order.Summary.OrderDate.ToString("dd/MM/yyyy hh:mm:ss");

or

lblOrderDate.Text = string.Format("{0:dd/MM/yyyy hh:mm:ss}", order.Summary.OrderDate);

or like @fhogberg

lblOrderDate.Text = order.Summary.OrderDate.ToLongDateString();

Upvotes: 0

Related Questions