PC Review


Reply
Thread Tools Rate Thread

DateTimePicker and UTC datetime

 
 
Pedro Rosas Silva
Guest
Posts: n/a
 
      2nd Dec 2008
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
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      2nd Dec 2008
Pedro Rosas Silva wrote:
> 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/VisualS...dbackID=283718)


Armin

 
Reply With Quote
 
Pedro Rosas Silva
Guest
Posts: n/a
 
      3rd Dec 2008
On Dec 2, 4:32*pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
> Pedro Rosas Silva wrote:
> > 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/VisualS...Feedback.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/b...d-setting.aspx


Best Regards,
Pedro Rosas Silva
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      3rd Dec 2008
Pedro Rosas Silva wrote:
> On Dec 2, 4:32 pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
>> Pedro Rosas Silva wrote:
>>> 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/VisualS...Feedback.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,


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/b...d-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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare datetime value from datetimepicker with value within db Mike Microsoft C# .NET 5 27th Nov 2007 07:23 PM
Millisecond values missing when inserting datetime into datetime column of sql Server Manikandan Microsoft C# .NET 4 18th Jul 2007 08:59 PM
How can I save a DateTime from my C# program into a SQL Server (datetime) database column. Steve Kershaw Microsoft ASP .NET 5 29th Aug 2006 03:10 AM
DateTime (DateTimePicker) SQLCE insert =?Utf-8?B?bWFyY21j?= Microsoft Dot NET Compact Framework 1 9th Jun 2004 08:47 PM
XML dateTime conversion to DateTime.MinValue accross timezones Symon R Microsoft Dot NET 0 6th Aug 2003 07:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:58 AM.