Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime picker C# format

I have a DateTime picker to add arrival time to a list, I have 2 questions about it:

  1. How can I get it to show dates like 12-Jan-2012 Instead of 12/01/12?
  2. How can I get it to show the time after the date but not the current time, as thats what is shows atm.

My current code is not very advanced its just:

theVisit.ArrivalTime = DateTimePicker1.Value
like image 468
TAM Avatar asked Dec 21 '22 12:12

TAM


1 Answers

Something like this will display the date and time:

DateTimePicker1.Value.ToString("d-MMM-yyyy hh:mm:ss");

To override the default DateTimePicker settings, you can do this:

DateTimePicker1.Format = DateTimePickerFormat.Custom;
DateTimePicker1.CustomFormat = "d-MMM-yyyy  hh:mm:ss";

You can show a different time by modifying the format string, e.g.:

DateTimePicker1.CustomFormat = "d-MMM-yyyy 12:00:00";

or even

DateTime otherTime = DateTime.Now;
DateTimePicker1.CustomFormat = "d-MMM-yyyy " + otherTime.ToString("hh:mm:ss");
like image 168
Peter Gluck Avatar answered Dec 23 '22 02:12

Peter Gluck