views:

436

answers:

3

Hi All, I am developing an application in which I am trying to fetch Date, Time and Time Zone from single DateTimePicker control. Can anybody help to resolve this? Thanks in advance.

EditV1: I am using .net framework 2.0. Now I am able to fetch Date and Time with Single DateTimepicker by setting its CustomFormat property as;
dtpicker2.CustomFormat = "MM/dd/yyyy,hh:mm:ss"
Now my problem is to fetch TimeZone.

EditV2: Now here is one more issue, if I set DateTimePicker's format property to Time, it shows me something like 2:30:00 PM. I am storing this in a file and reasigning it to the DateTimePicker control. Can anybody help me out, how to achieve this?

A: 

Using the DateTimePicker you can change the Format Property to Custom, and specify the CustomFormat Property as dd MMM yyyy hh:mm:ss. This will allow you to in your code use

DateTime dt = dateTimePicker1.Value;
dt.Date
dt.TimeOfDay

Unfortunately the DateTimePicker does not have the built in TimeZone but you can make use of

TimeZone tz = TimeZone.CurrentTimeZone;

Also have a look at this Question

Custom Formating a DateTimePicker using CultureInfo

astander
A: 

You won't be able to do it using a DateTimePicker on it's own.

Rather, you are going to have to have sort of composite control which has a DateTimePicker on it, as well as another control which will serve as the offset.

This control could be a numeric up/down control which you would use for the hour, minute, second, etc, etc offset (or just a textbox for that matter).

Another option is if you have a location (in the form of latitude and longitude, which you can obtain via Google through HTTP if you have an address), to use the Timezone API function at GeoNames which will allow you to pass a latitude and longitude value and it will return the timezone for that location. That, along with the TZ database and the ZoneInfo project will allow you to determine the offset at that particular date/time (which isn't the same for all locations and all dates).

casperOne
I was about to +1... until the mention of geocoding. Don't do it, chaps, especially for defaults for UIs: it's really very very unreliable and will just annoy your users.
Jeremy McGee
@Jeremy McGee: Note how I said if you have an address. I believe you think I'm implying one should geocode by IP address, which I agree, is *very* unreliable. Geocoding doesn't imply using an IP address to resolve physical location. If one has an address, Google does an excellent job of translating that to a lat/long pair consistently and accurately.
casperOne
Thanks for the replies. Actually, I am developing a windows application, in which I was trying to get input as Date, Time and Time Zone. I found out the way to get Date and Time, with 2 different DateTimePicker controls, of course it can be achieved with single control, but I used 2 for the sake of simplicity. I have found one class which is equivalent to TimeZoneInfo in .net 3.5. Now I am making use of this class.
Vijay Balkawade
A: 

The Any+Time(TM) Datepicker/Timepicker AJAX Calendar Widget now supports time zone input/output, selection and conversion. It should be compatible with .NET (see the Troubleshooting section on the web page if you have problems) and has pretty extensive timezone support (see the section on the web page about UTC offsets). Hopefully it will meet your needs.

Andrew M. Andrews III