Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting ToShortDateString to dd/MM/yyyy

Tags:

I have Calendar like this one:

View

 <td>      <asp:Calendar ID="Calendar1" runat="server"        OnSelectionChanged="DateChange">      </asp:Calendar>      <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  </td> 

.Cs file

protected void Page_Load(object sender, EventArgs e)     {         TextBox2.Text = DateTime.Today.ToShortDateString()+'.';     }      protected void DateChange(object sender, EventArgs e)     {         TextBox2.Text = Calendar1.SelectedDate.ToShortDateString() + '.';     } 

It display date as "MM/dd/yyyy", but I want to display it as "dd/MM/yyyy", I try it changing DateTime.Today.ToShortDateString()+'.'; to DateTime.Today.ToShortDateString("dd/MM/yyyy");

but I get

Error 3 No overload for method 'ToShortDateString' takes 1 arguments

What can I do to solve this?

like image 435
Pepe Avatar asked Oct 20 '17 21:10

Pepe


People also ask

How to use ToShortDateString in c#?

ToShortDateString() Method in C# The DateTime. ToShortDateString() method in C# is used to convert the value of the current DateTime object to its equivalent short date string representation.

How to get date format uipath?

ParseExact: This method can be used when you want to get exact format of date. There are different arguments which you need to pass while converting to a format. Value: It is string representation of date and time.


1 Answers

ToShortDateString does not have an overload which takes any parameter.

If your ToShortDateString() returns MM/dd/yyyy format, that means your CurrentCulture has this format in it's ShortDatePattern property.

You can always use custom formatting for that like with proper culture like;

TextBox2.Text = DateTime.Today.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); 
like image 96
Soner Gönül Avatar answered Oct 22 '22 09:10

Soner Gönül