DateTimePicker and UTC datetime

  • Thread starter Pedro Rosas Silva
  • Start date
P

Pedro Rosas Silva

Hello Everyone,

I want to build/use a control that allows the user to select a UTC
datetime.
As far as I am concerned, DateTimePicker allows the user to select a
datetime based on the local culture settings.
Is it possible to change this and force the selection to be done in
UTC datetime instead of the local culture settings?
How could it be done?
Please advice if you have any idea.
Thanks in advance.


Best Regards,
Pedro Rosas Silva
 
A

Armin Zingler

Pedro said:
Hello Everyone,

I want to build/use a control that allows the user to select a UTC
datetime.
As far as I am concerned, DateTimePicker allows the user to select a
datetime based on the local culture settings.
Is it possible to change this and force the selection to be done in
UTC datetime instead of the local culture settings?
How could it be done?
Please advice if you have any idea.
Thanks in advance.


I don't think so. Though, you can easily reinterpret it:

Dim ValueUTC = DateTime.SpecifyKind(DTP.value, DateTimeKind.Utc)

Or, you can store it in a DateTimeOffset object:

Dim DTO = New DateTimeOffset(ValueUTC)


Interesting IMO:
http://msdn.microsoft.com/en-us/library/bb384267.aspx


Also be aware that there's still a bug showing the 'Kind' value in the
immediate window or using the tooltip (at least in VB 2008).
(http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=283718)


Armin
 
P

Pedro Rosas Silva

I don't think so. Though, you can easily reinterpret it:

Dim ValueUTC = DateTime.SpecifyKind(DTP.value, DateTimeKind.Utc)

Or, you can store it in a DateTimeOffset object:

Dim DTO = New DateTimeOffset(ValueUTC)

Interesting IMO:http://msdn.microsoft.com/en-us/library/bb384267.aspx

Also be aware that there's still a bug showing the 'Kind' value in the
immediate window or using the tooltip (at least in VB 2008).
(http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?...)

Armin


Thank you Armin.
I used the SpecifyKind method and I managed to solve my problem.

But, anyway, there is a intersting "feature?" in the 'DateTimePicker'
control.
Whenever you try to change its 'DateTime' property, the 'Kind'
property is lost.
It seems that the 'Kind' property is inherited and is always set to
'Unspecified':

http://drowningintechnicaldebt.com/...ker-control-and-its-datetimekind-setting.aspx


Best Regards,
Pedro Rosas Silva
 
A

Armin Zingler

Pedro said:
Thank you Armin.
I used the SpecifyKind method and I managed to solve my problem.

But, anyway, there is a intersting "feature?" in the 'DateTimePicker'
control.
Whenever you try to change its 'DateTime' property,

You mean the Value property.?
the 'Kind'
property is lost.
It seems that the 'Kind' property is inherited and is always set to
'Unspecified':

http://drowningintechnicaldebt.com/...ker-control-and-its-datetimekind-setting.aspx

I guess it's not what you described but it's the IDE bug I've described in
my first post: Displaying the value is buggy, not the assignment to the
value. Try this:

Dim dt = Now
MsgBox(dt.Kind.ToString)
DateTimePicker1.Value = dt
dt = DateTimePicker1.Value
MsgBox(dt.Kind.ToString)

I get "Local" twice. Though, evaluating dt.kind during debugging, it always
displays 'Unspecified'. Have a look at the link I posted.


Armin
 

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

Top