DateTimePicker...

  • Thread starter Thread starter Robson
  • Start date Start date
R

Robson

How do I display the date AND the time in the date/time picker? If I use a
custom format, how can I do this AND stick to local date/time display rules?


Thanks,



Robin
 
Robson,

Just set the value of the datetime to a proper date.

By instance roughly typed here

mydatetimepicker1.value = Now

I hope this helps,

Cor
 
Yes, I'm doing that now to set the intial date, but it just displays the
date part, not the time part. I can set it to show long date, short date or
time, but I want to show Date Time ( DD/MM/YYYY HH:MM:SS or equivalent for
the given locale) in the actual control.
 
Robson,

I assume that you ask how the datetimepicker interacts with the
Iformatprovider as far as I can see does it that only with the custom
paterns from that, and can you not reach your goal because you need the (f
or F) from that (not existing ShortDateTimePattern) however which exist as
"f".

You should can set two datetimepickers however that you would have seen
probably already

Or you can localize your applications and test the currentuicultures and set
accoording to those than the custom paterns (not nice in an age of
globalization in my idea too).

Sorry, I have no other answer for you.

However, I find it a very interesting question and will ask it somewhere
else.

Cor
 
Robson,
In addition to the other comments.

I normally use 2 datetime picker controls. One for the Date AND one for the
Time.

To keep the two values "in sync" I normally use code similar to:

Private Sub pickerDate_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles pickerDate.ValueChanged
pickerTime.Value =
pickerDate.Value.Date.Add(pickerTime.Value.TimeOfDay)
End Sub

Private Sub pickerTime_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles pickerTime.ValueChanged
Me.labelDateTime.Text = pickerTime.Value.ToString()
End Sub

In the above case I would use pickerTime.Value as the full date time value.


I normally use the following properties on the Time picker:

Format = Custom
CustomFormat = "HH:mm" (for 24 hour:min)
ShowUpDown = True


I normally encapsulate both date time picker controls in a User control that
has properties to simplify the getting & setting values...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| How do I display the date AND the time in the date/time picker? If I use
a
| custom format, how can I do this AND stick to local date/time display
rules?
|
|
| Thanks,
|
|
|
| Robin
|
|
|
 
Yes, I thought about this also, but it doesn't seem too clean to me.
Anyway, that seems to be the workaround at least for now.
 
Robson said:
How do I display the date AND the time in the date/time picker? If I use
a custom format, how can I do this AND stick to local date/time display
rules?

\\\
With Me.DateTimePicker1
.Format = DateTimePickerFormat.Custom
.CustomFormat = _
CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern
End With
///
 
Herfried,

Smart,

And to fullfill the asked question in the thread about the shortformat
complete

\\\
.CustomFormat = _
CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern & " " & _
CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern
///

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top