如何从单个DateTimePicker控件获取日期,时间和时区 [英] How to: get Date, Time and Time zone from single DateTimePicker Control
问题描述
我正在开发一个应用程序,我正在尝试从单个 DateTimePicker
控件中获取日期,时间和时区。有人可以帮助解决这个问题吗?
编辑1
我正在使用.NET Framework 2.0。现在,通过将其 CustomFormat
属性设置为
DateTimePicker
获取日期和时间$ b
dtpicker2.CustomFormat =MM / dd / yyyy,hh:mm:ss
现在我的问题是获取TimeZone。
编辑2
现在这里还有一个问题,如果我将 DateTimePicker
的format属性设置为Time,它会显示一些类似 2:30:00 PM
。我正在将其存储在一个文件中,并将其重新分配给 DateTimePicker
控件。
任何人可以帮助我,如何实现?
您将无法使用它自己的DateTimePicker来执行。
<相反,您将需要一种具有DateTimePicker的组合控件,以及将用作偏移量的另一个控件。
控制可以是一个数字上/下控制,您将用于小时,分钟,秒等等的偏移量(或只是一个文本框)。
另一个选择是,如果你有一个位置(以经度的形式,您可以通过HTTP获取HTTP,如果您有地址),请使用 GeoNames上的时区API函数,它将允许您传递纬度和经度值,并返回该位置的时区。这与 TZ数据库和 ZoneInfo项目将允许您确定该特定日期/时间的偏移量(对于所有位置和所有日期不同) 。
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?
Edit 1
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.
Edit 2
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 reassigning it to the DateTimePicker
control.
Can anybody help me out, how to achieve this?
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).
这篇关于如何从单个DateTimePicker控件获取日期,时间和时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!