473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Timezone conversion

I have an events table which stores the time of each event - the time and
assoicated timezone. Is there a way of converting this time into GMT (with
support for DST).. some sort of function which accepts a time and timezone
as parameters and returns the time in GMT?
Nov 19 '05 #1
6 2446
Microsoft recommends using UTC time (universal Time Coordinate)...similar to
the GMT concept. If you use that...

DateTime.ToLocalTime()
DateTime.ToUniversalTime()

If you want GMT, you'll have to write your own utility class.

-Jason

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
I have an events table which stores the time of each event - the time and
assoicated timezone. Is there a way of converting this time into GMT (with
support for DST).. some sort of function which accepts a time and timezone
as parameters and returns the time in GMT?

Nov 19 '05 #2
these functions wont allow me to convert a time in Pacific time to UTC..
will they?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Microsoft recommends using UTC time (universal Time Coordinate)...similar to the GMT concept. If you use that...

DateTime.ToLocalTime()
DateTime.ToUniversalTime()

If you want GMT, you'll have to write your own utility class.

-Jason

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
I have an events table which stores the time of each event - the time and
assoicated timezone. Is there a way of converting this time into GMT (with support for DST).. some sort of function which accepts a time and timezone as parameters and returns the time in GMT?


Nov 19 '05 #3
Yes they will. Let's say you need to convert the current time.

DateTime currentTime = DateTime.Now;
DateTime utcTime = currentTime.ToUniveralTime();

or the short version: DateTime utcTime = DateTime.Now.ToUniversalTime();

If you need to use a date other than "now":

DateTime myDate = DateTime.Parse("7/4/2004 13:00:00");
DateTime utcTime = myDate.ToUniversalTime();

the short version: DateTime utcTime = DateTime.Parse("7/4/2004
13:00:00").ToUniversalTime();

To convert back:

DateTime myDate = utcTime.ToLocalTime();

Of course, this example assumes you are using the timezone of the machine
the application lives on. If you're on the east cost and need to convert to
pacific, you can use the Calendar Object to set the locale and pull your
dates/times from that. Though, if you need that flexability, and are going
to bu reusing that code, I would take the custom utility class approach.
"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
these functions wont allow me to convert a time in Pacific time to UTC..
will they?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Microsoft recommends using UTC time (universal Time Coordinate)...similar

to
the GMT concept. If you use that...

DateTime.ToLocalTime()
DateTime.ToUniversalTime()

If you want GMT, you'll have to write your own utility class.

-Jason

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
>I have an events table which stores the time of each event - the time
>and
> assoicated timezone. Is there a way of converting this time into GMT (with > support for DST).. some sort of function which accepts a time and timezone > as parameters and returns the time in GMT?
>
>



Nov 19 '05 #4
do u have any examples of the calendar object?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
Yes they will. Let's say you need to convert the current time.

DateTime currentTime = DateTime.Now;
DateTime utcTime = currentTime.ToUniveralTime();

or the short version: DateTime utcTime = DateTime.Now.ToUniversalTime();

If you need to use a date other than "now":

DateTime myDate = DateTime.Parse("7/4/2004 13:00:00");
DateTime utcTime = myDate.ToUniversalTime();

the short version: DateTime utcTime = DateTime.Parse("7/4/2004
13:00:00").ToUniversalTime();

To convert back:

DateTime myDate = utcTime.ToLocalTime();

Of course, this example assumes you are using the timezone of the machine
the application lives on. If you're on the east cost and need to convert to pacific, you can use the Calendar Object to set the locale and pull your
dates/times from that. Though, if you need that flexability, and are going to bu reusing that code, I would take the custom utility class approach.
"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
these functions wont allow me to convert a time in Pacific time to UTC..
will they?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Microsoft recommends using UTC time (universal Time
Coordinate)...similar to
the GMT concept. If you use that...

DateTime.ToLocalTime()
DateTime.ToUniversalTime()

If you want GMT, you'll have to write your own utility class.

-Jason

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
>I have an events table which stores the time of each event - the time
>and
> assoicated timezone. Is there a way of converting this time into GMT

(with
> support for DST).. some sort of function which accepts a time and

timezone
> as parameters and returns the time in GMT?
>
>



Nov 19 '05 #5
Sorry... in Java mode these days... The Calendar class in .Net doesn't allow
you to set the timezone. There is a TimeZone class, but it also uses the
timezone of the current computer.

Looks like, if you want that flexability, you're going to have to write you
own. You could Inherit the TimeZone class (DateTime is a structure and not
inheritable) and overload the ToLocalTime() method. That way, your new
class has all the other functionality you need to work with TimeZones and
UTC time.

Something like....

public DateTime ToLocalTime(DateTime dt, string tz) {
if (tz.ToLower().Equals("pst")) {
return dt.AddHours(-8);
}
}

Obviously, you'll have to get a litte more fancy to get around the daylight
savings time problem. You'll have to test it to get the math right, but you
can use the TimeZone.IsDaylightSavingTime method coupled with the
DaylightTime class to check if the date is within daylight savings time.

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
do u have any examples of the calendar object?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
Yes they will. Let's say you need to convert the current time.

DateTime currentTime = DateTime.Now;
DateTime utcTime = currentTime.ToUniveralTime();

or the short version: DateTime utcTime = DateTime.Now.ToUniversalTime();

If you need to use a date other than "now":

DateTime myDate = DateTime.Parse("7/4/2004 13:00:00");
DateTime utcTime = myDate.ToUniversalTime();

the short version: DateTime utcTime = DateTime.Parse("7/4/2004
13:00:00").ToUniversalTime();

To convert back:

DateTime myDate = utcTime.ToLocalTime();

Of course, this example assumes you are using the timezone of the machine
the application lives on. If you're on the east cost and need to convert

to
pacific, you can use the Calendar Object to set the locale and pull your
dates/times from that. Though, if you need that flexability, and are

going
to bu reusing that code, I would take the custom utility class approach.
"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
> these functions wont allow me to convert a time in Pacific time to
> UTC..
> will they?
>
> "Jason Penniman" <jp*******@actcci.com> wrote in message
> news:%2******************@TK2MSFTNGP10.phx.gbl...
>> Microsoft recommends using UTC time (universal Time Coordinate)...similar > to
>> the GMT concept. If you use that...
>>
>> DateTime.ToLocalTime()
>> DateTime.ToUniversalTime()
>>
>> If you want GMT, you'll have to write your own utility class.
>>
>> -Jason
>>
>> "Bijoy Naick" <b_*****@yahoo.ca> wrote in message
>> news:eq**************@TK2MSFTNGP09.phx.gbl...
>> >I have an events table which stores the time of each event - the time
>> >and
>> > assoicated timezone. Is there a way of converting this time into GMT
> (with
>> > support for DST).. some sort of function which accepts a time and
> timezone
>> > as parameters and returns the time in GMT?
>> >
>> >
>>
>>
>
>



Nov 19 '05 #6
I've been using the ToUniversalTime object with great success until we moved
the clocks forward for daylight savins time. Now, ToUniversalTime shows UTC
+ 1 hour. How can I compensate for this automatically?

Brett

"Jason Penniman" wrote:
Sorry... in Java mode these days... The Calendar class in .Net doesn't allow
you to set the timezone. There is a TimeZone class, but it also uses the
timezone of the current computer.

Looks like, if you want that flexability, you're going to have to write you
own. You could Inherit the TimeZone class (DateTime is a structure and not
inheritable) and overload the ToLocalTime() method. That way, your new
class has all the other functionality you need to work with TimeZones and
UTC time.

Something like....

public DateTime ToLocalTime(DateTime dt, string tz) {
if (tz.ToLower().Equals("pst")) {
return dt.AddHours(-8);
}
}

Obviously, you'll have to get a litte more fancy to get around the daylight
savings time problem. You'll have to test it to get the math right, but you
can use the TimeZone.IsDaylightSavingTime method coupled with the
DaylightTime class to check if the date is within daylight savings time.

"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
do u have any examples of the calendar object?

"Jason Penniman" <jp*******@actcci.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
Yes they will. Let's say you need to convert the current time.

DateTime currentTime = DateTime.Now;
DateTime utcTime = currentTime.ToUniveralTime();

or the short version: DateTime utcTime = DateTime.Now.ToUniversalTime();

If you need to use a date other than "now":

DateTime myDate = DateTime.Parse("7/4/2004 13:00:00");
DateTime utcTime = myDate.ToUniversalTime();

the short version: DateTime utcTime = DateTime.Parse("7/4/2004
13:00:00").ToUniversalTime();

To convert back:

DateTime myDate = utcTime.ToLocalTime();

Of course, this example assumes you are using the timezone of the machine
the application lives on. If you're on the east cost and need to convert

to
pacific, you can use the Calendar Object to set the locale and pull your
dates/times from that. Though, if you need that flexability, and are

going
to bu reusing that code, I would take the custom utility class approach.
"Bijoy Naick" <b_*****@yahoo.ca> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
> these functions wont allow me to convert a time in Pacific time to
> UTC..
> will they?
>
> "Jason Penniman" <jp*******@actcci.com> wrote in message
> news:%2******************@TK2MSFTNGP10.phx.gbl...
>> Microsoft recommends using UTC time (universal Time

Coordinate)...similar
> to
>> the GMT concept. If you use that...
>>
>> DateTime.ToLocalTime()
>> DateTime.ToUniversalTime()
>>
>> If you want GMT, you'll have to write your own utility class.
>>
>> -Jason
>>
>> "Bijoy Naick" <b_*****@yahoo.ca> wrote in message
>> news:eq**************@TK2MSFTNGP09.phx.gbl...
>> >I have an events table which stores the time of each event - the time
>> >and
>> > assoicated timezone. Is there a way of converting this time into GMT
> (with
>> > support for DST).. some sort of function which accepts a time and
> timezone
>> > as parameters and returns the time in GMT?
>> >
>> >
>>
>>
>
>



Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jim Davis | last post by:
I'm (still) working on an ISO 8601 date parser. I want to convert at least the formats described here: http://www.w3.org/TR/NOTE-datetime Well.. I've got most of it working (via RegEx's) good...
1
by: cnliou | last post by:
Hi! If I correctly understand v7.4 manual, value, say, '2003-11-26 12:00' in TIMESTAMP WITHOUT TIMEZONE column should output '2003-11-26 19:00' for "+08:00" timezone. The following test...
2
by: Jeanine | last post by:
I'am looking for a php script to make a time conversion between timezones. Any idea ? Thanks in advance, Jeanine
0
by: Ninja Zombie | last post by:
Hi all, is there maybe a property on the JCC driver which, when set, will convert the selected TIMESTAMP attribute to my local timezone. The database server is in the different timezone than the...
1
by: mmv | last post by:
Hello, Given Datetime value in a string, I wish to write a code where in I could convert the datetime to a value in particular timezone. For example, If the given datetime is 10:00 am in CST, i...
2
by: Benjamin The Donkey | last post by:
How do I convert Date to another TimeZone in C#? I am using .NET 1.1 right now.
5
by: Ivan Velev | last post by:
Hello, Minimal example below - it gives me different output if I comment / uncomment the extra time.mktime call - note that this call is not related in any way to main logic flow. When...
1
by: Ajinkya | last post by:
Hello Friends, I want to convert server timezone (GMT) to Indian timezone (IST). Tell me any method or give me some code for it.
4
by: reach2raziq | last post by:
Hi All, I have one web site and server that is hosted on "Pacific Standard Time" Zone . When a user from different contries creat blogs the displayed time for respective blog will be a server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.