I have a datetimepicker which on loading of windows form shows me format in 'MM-dd-yyyy',
as follows:
I would like it in dd-MM-yyyy
.
I tried the following:
set custom format: "dd-MM-yyyy"
But Its not changing.
What could be the problem?
Please help me.
var year = 2014; var month = 5; var day = 10; var realDate = new Date(year, month - 1, day); // months are 0-based! $('#MainContent_txtDataConsegna'). datepicker({ dateFormat: 'dd/mm/yyyy' }); // format to show $('#MainContent_txtDataConsegna'). datepicker('setDate', realDate);
In order to set the date format, we only need to add format of one argument and then we will add our required format, which is shown in the following example: Example 1: In this example, we are going to use dd-mm-yyyy format.
In Windows Forms, the DateTimePicker control is used to select and display the date/time with a specific format in your form.
Ensure that control Format property is properly set to use a custom format:
DateTimePicker1.Format = DateTimePickerFormat.Custom
Then this is how you can set your desired format:
DateTimePicker1.CustomFormat = "dd-MM-yyyy"
Ammending as "optional Answer". If you don't need to programmatically solve the problem, here goes the "visual way" in VS2012.
In Visual Studio, you can set custom format directly from the properties Panel:
First Set the "Format" property to: "Custom"; Secondly, set your custom format to: "dd-MM-yyyy";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With