| Time Zone Conversion Demo |
|
This demo converts the date/time value you enter into UTC and Local time, based
on the selected timezone.
|
|
Timezone:
|
|
| Date: |
|
| Time: |
|
| |
|
|
TimeZoneSource.com Solution for Microsoft .Net
The TimeZoneSource.com Solution for Microsoft .Net is ideal for projects where
you need to store date/time values in UTC format and you have users that work
in multiple time zones.
Code Examples: [C#]
using TimeZoneSourceCode;
// ** Fill a drop down list with timezones.
ddlTimeZones.DataSource = new TimeZoneSource();
ddlTimeZones.DataValueField = "TimeZone_Code";
ddlTimeZones.DataTextField = "TimeZone_Name";
ddlTimeZones.DataBind();
// ** Convert a local date/time value to UTC
TimeZoneSource tzs = new TimeZoneSource();
// Get User's timezone code from data, form, etc.
int intTimeZoneCode = 4;
// Get the utc DateTime value from data, form, etc.
DateTime utcDate = new DateTime(2005, 7, 1, 9, 0, 0);
// Convert utcDate to a Local DateTime value.
DateTime localDateTime = tzs.ConvertUtcToLocal(intTimeZoneCode, utcDate);
// ** Convert a UTC date/time value to local
TimeZoneSource tzs = new TimeZoneSource();
// Get User's timezone code from data, form, etc.
int intTimeZoneCode = 4;
// Get the local DateTime value from data, form, etc.
DateTime localDate = new DateTime(2005, 7, 1, 9, 0, 0);
// Convert localDate to a UTC DateTime value.
DateTime utcDateTime = tzs.ConvertLocalToUtc(intTimeZoneCode, localDate);
|
TimeZoneSource.com Solution for Microsoft SQL Server
If you prefer to handle the date/time conversions inside SQL stored procedures,
then the TimeZoneSource.com Solution for Microsoft SQL Server is the right
choice for you.
Script Examples:
// ** Convert a local date/time value to UTC
CREATE PROCEDURE [dbo].[SomeProc]
(
@ID int,
@TimeZoneCode tinyint,
@LocalDate datetime
)
AS
UPDATE dbo.tblSomeTable SET
SOME_UTC_DATE_FIELD = dbo.udfConvertToUtc(@TimeZoneCode, @LocalDate)
WHERE (ID = @ID)
GO
// ** Convert a UTC date/time value to local time
CREATE PROCEDURE [dbo].[SomeProc]
(
@ID int,
@TimeZoneCode tinyint
)
AS
SELECT dbo.udfConvertToLocal(@TimeZoneCode, SOME_UTC_DATE_FIELD) AS
LocalDateTime
FROM dbo.tblSomeTable
WHERE (ID = @ID)
GO
|
About the TimeZoneSource Data
|
The correct way to handle time zone offsets is to adjust your date/time data
based on daylight savings rules. These rules are different for each time zone,
and unfortunately the rules can change from year to year.
The rules define whether or not a time zone observes daylight savings, when
daylight saving starts, and what the offset minutes should be relative to UTC.
Included with your purchase is a detailed time zone rules data set (either in
an XML format or in a SQL table). We use this data to determine the offset
minutes as we convert date/time data from one time zone to another.
The rules data has been compiled from a number of resources provided by Microsoft. We
believe this data to be as accurate and up-to-date as possible, but as
mentioned earlier, the rules do change frequently. But now that you have the
data, you can manage the rules yourself, as needed, to ensure your data
continues to be accurate.
|
|
|