Analytics


Google

Tuesday, March 25, 2008

Timezone support in Application

Oracle Support of TimeZone

The following article provides a very good explanation on how timezone support in Oracle.

http://www.devx.com/dbzone/Article/30501

The following function is extract from the article above:


create or replace FUNCTION
convert_time(datetime IN TIMESTAMP, tz1 IN VARCHAR2, tz2 IN VARCHAR2)
RETURN TIMESTAMP WITH TIME ZONE AS
retval TIMESTAMP WITH TIME ZONE;
/*
Obtained from http://www.devx.com/dbzone/Article/30501
Date: Mar 25, 2008

Note:
List of timezones available via

select * from V$TIMEZONE_NAMES

More reference:
http://toolkit.rdbms-insight.com/tz.php

Sample usage:
select to_char(convert_time(sysdate, 'Asia/Kuala_Lumpur', 'US/Mountain'), 'dd-MON-yyyy HH24:mi') cDate from dual
*/

BEGIN

retval := from_tz(datetime, tz1) AT TIME ZONE tz2;
RETURN retval;

END;


The following a sample of how to use the above function:

select convert_time(sysdate, 'Asia/Kuala_Lumpur', 'US/Mountain') from dual;

select to_char(convert_time(sysdate, 'Asia/Kuala_Lumpur', 'US/Mountain'), 'dd-MON-yyyy HH24:mi') cDate from dual;



Some useful links related to this is found at the following url:

http://stanford.edu/dept/itss/docs/oracle/10g/server.101/b10749/ch4datetime.htm
http://www.dbasupport.com/oracle/ora9i/TimeZone.shtml
http://toolkit.rdbms-insight.com/tz.php



.Net Framework 1.1 and 2.0 does not have an easy way to convert time to the various timezone. It is necessary to manually calculate the offset and then perform the computation. This is a problem due to the changing daylight savings. However, the following is a good library recommended by several sites to help with the conversion:

http://www.michaelbrumm.com/simpletimezone.html





VB.NET Framework 3.5

TimeZoneInfo.ConvertTimeBySystemTimeZoneId(oldTime, FromZoneId, ToZoneId)

The list of TimeZone IDs are as follows:

Greenwich Standard Time
GMT Standard Time
W. Europe Standard Time
Central Europe Standard Time
Romance Standard Time
Central European Standard Time
W. Central Africa Standard Time
Jordan Standard Time
GTB Standard Time
Middle East Standard Time
Egypt Standard Time
South Africa Standard Time
FLE Standard Time
Israel Standard Time
E. Europe Standard Time
Namibia Standard Time
Arabic Standard Time
Arab Standard Time
Russian Standard Time
E. Africa Standard Time
Georgian Standard Time
Iran Standard Time
Arabian Standard Time
Azerbaijan Standard Time
Caucasus Standard Time
Armenian Standard Time
Afghanistan Standard Time
Ekaterinburg Standard Time
West Asia Standard Time
India Standard Time
Sri Lanka Standard Time
Nepal Standard Time
N. Central Asia Standard Time
Central Asia Standard Time
Myanmar Standard Time
SE Asia Standard Time
North Asia Standard Time
China Standard Time
North Asia East Standard Time
Singapore Standard Time
W. Australia Standard Time
Taipei Standard Time
Tokyo Standard Time
Korea Standard Time
Yakutsk Standard Time
Cen. Australia Standard Time
AUS Central Standard Time
E. Australia Standard Time
AUS Eastern Standard Time
West Pacific Standard Time
Tasmania Standard Time
Vladivostok Standard Time
Central Pacific Standard Time
New Zealand Standard Time
Fiji Standard Time
Tonga Standard Time
Azores Standard Time
Cape Verde Standard Time
Mid-Atlantic Standard Time
E. South America Standard Time
SA Eastern Standard Time
Greenland Standard Time
Montevideo Standard Time
Newfoundland Standard Time
Atlantic Standard Time
SA Western Standard Time
Central Brazilian Standard Time
Pacific SA Standard Time
Venezuela Standard Time
SA Pacific Standard Time
Eastern Standard Time
US Eastern Standard Time
Central America Standard Time
Central Standard Time
Central Standard Time (Mexico)
Mexico Standard Time
Canada Central Standard Time
US Mountain Standard Time
Mountain Standard Time (Mexico)
Mexico Standard Time 2
Mountain Standard Time
Pacific Standard Time
Pacific Standard Time (Mexico)
Alaskan Standard Time
Hawaiian Standard Time
Samoa Standard Time
Dateline Standard Time


Sample code is as follows:

' Time Zone Class
' Author Strovek
' Date Mar 25, 2008
' Revised

Public Class tZone

Public Shared Function Version() As String
With _
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
Return .FileMajorPart & "." & .FileMinorPart & "." & .FileBuildPart & "." & .FilePrivatePart
End With
End Function

Public Sub listTimeZone()
Dim aList As System.Collections.ObjectModel.ReadOnlyCollection(Of TimeZoneInfo)
Dim tInfo As TimeZoneInfo

aList = System.TimeZoneInfo.GetSystemTimeZones()

For Each tInfo In aList
Console.WriteLine(tInfo.Id)
Next

End Sub

Public Sub displayTime()
Dim vTime As DateTime = Now
Dim vTime2 As DateTime

Try

vTime2 = convTime(vTime, "Singapore Standard Time", "Mountain Standard Time")

Console.WriteLine(String.Format("Time converted from {0} to {1}", vTime, vTime2))
Catch ex As Exception
Throw New Exception("[displayTime01]" & ex.Message)
End Try


End Sub

Public Function convTime(ByVal pTime As DateTime, ByVal pFromZone As String, ByVal pToZone As String) As DateTime
Dim vTime As DateTime
Try
vTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(pTime, pFromZone, pToZone)
Catch ex As Exception
Throw New Exception("[convTime01]" & ex.Message)
End Try
convTime = vTime
End Function

Public Shared Sub Main(ByVal args() As String)
Dim tZObj As New tZone
Console.WriteLine("Start TimeZone - Version " & tZone.Version())
Try
tZObj.listTimeZone()
tZObj.displayTime()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.WriteLine("End Program")
End Sub

End Class





Java TimeZone (JDK 1.6)


This is based on the information obtained from here.
The code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package tzone;

/**
*
* @author strovek
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Program start");
tZone tzObj = new tZone();
tzObj.listZone();
tzObj.printDate();
System.out.println("Program End");

}

}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package tzone;

import java.text.DateFormat;
import java.util.TimeZone;
import java.util.Locale;

/**
*
* @author strovek
*/
public class tZone {

public void printDate() {
java.util.Date cDate = new java.util.Date();
TimeZone tzFrom, tzTo, localZone;
Locale lZone = Locale.ENGLISH;
DateFormat dForm = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, lZone);

tzFrom = TimeZone.getTimeZone("Asia/Bangkok");
tzTo = TimeZone.getTimeZone("US/Mountain");

System.out.println("Current time " + cDate);
dForm.setTimeZone(tzFrom);
System.out.println("From Date - " + dForm.format(cDate));
dForm.setTimeZone(tzTo);
System.out.println("To Date - " + dForm.format(cDate));

}

public void listZone() {
String aList[];
int loopCnt;

aList = java.util.TimeZone.getAvailableIDs();
loopCnt = 0;
while (loopCnt < aList.length) {
System.out.println(aList[loopCnt]);
loopCnt++;
}
}
}

==========

Output:


Program start
Etc/GMT+12
Etc/GMT+11
MIT
Pacific/Apia
Pacific/Midway
Pacific/Niue
Pacific/Pago_Pago
Pacific/Samoa
US/Samoa
America/Adak
America/Atka
Etc/GMT+10
HST
Pacific/Fakaofo
Pacific/Honolulu
Pacific/Johnston
Pacific/Rarotonga
Pacific/Tahiti
SystemV/HST10
US/Aleutian
US/Hawaii
Pacific/Marquesas
AST
America/Anchorage
America/Juneau
America/Nome
America/Yakutat
Etc/GMT+9
Pacific/Gambier
SystemV/YST9
SystemV/YST9YDT
US/Alaska
America/Dawson
America/Ensenada
America/Los_Angeles
America/Tijuana
America/Vancouver
America/Whitehorse
Canada/Pacific
Canada/Yukon
Etc/GMT+8
Mexico/BajaNorte
PST
PST8PDT
Pacific/Pitcairn
SystemV/PST8
SystemV/PST8PDT
US/Pacific
US/Pacific-New
America/Boise
America/Cambridge_Bay
America/Chihuahua
America/Dawson_Creek
America/Denver
America/Edmonton
America/Hermosillo
America/Inuvik
America/Mazatlan
America/Phoenix
America/Shiprock
America/Yellowknife
Canada/Mountain
Etc/GMT+7
MST
MST7MDT
Mexico/BajaSur
Navajo
PNT
SystemV/MST7
SystemV/MST7MDT
US/Arizona
US/Mountain
America/Belize
America/Cancun
America/Chicago
America/Costa_Rica
America/El_Salvador
America/Guatemala
America/Indiana/Knox
America/Indiana/Tell_City
America/Knox_IN
America/Managua
America/Menominee
America/Merida
America/Mexico_City
America/Monterrey
America/North_Dakota/Center
America/North_Dakota/New_Salem
America/Rainy_River
America/Rankin_Inlet
America/Regina
America/Swift_Current
America/Tegucigalpa
America/Winnipeg
CST
CST6CDT
Canada/Central
Canada/East-Saskatchewan
Canada/Saskatchewan
Chile/EasterIsland
Etc/GMT+6
Mexico/General
Pacific/Easter
Pacific/Galapagos
SystemV/CST6
SystemV/CST6CDT
US/Central
US/Indiana-Starke
America/Atikokan
America/Bogota
America/Cayman
America/Coral_Harbour
America/Detroit
America/Eirunepe
America/Fort_Wayne
America/Grand_Turk
America/Guayaquil
America/Havana
America/Indiana/Indianapolis
America/Indiana/Marengo
America/Indiana/Vevay
America/Indiana/Winamac
America/Indianapolis
America/Iqaluit
America/Jamaica
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Lima
America/Louisville
America/Montreal
America/Nassau
America/New_York
America/Nipigon
America/Panama
America/Pangnirtung
America/Port-au-Prince
America/Porto_Acre
America/Resolute
America/Rio_Branco
America/Thunder_Bay
America/Toronto
Brazil/Acre
Canada/Eastern
Cuba
EST
EST5EDT
Etc/GMT+5
IET
Jamaica
SystemV/EST5
SystemV/EST5EDT
US/East-Indiana
US/Eastern
US/Michigan
America/Anguilla
America/Antigua
America/Aruba
America/Asuncion
America/Barbados
America/Blanc-Sablon
America/Boa_Vista
America/Campo_Grande
America/Caracas
America/Cuiaba
America/Curacao
America/Dominica
America/Glace_Bay
America/Goose_Bay
America/Grenada
America/Guadeloupe
America/Guyana
America/Halifax
America/La_Paz
America/Manaus
America/Martinique
America/Moncton
America/Montserrat
America/Port_of_Spain
America/Porto_Velho
America/Puerto_Rico
America/Santiago
America/Santo_Domingo
America/St_Kitts
America/St_Lucia
America/St_Thomas
America/St_Vincent
America/Thule
America/Tortola
America/Virgin
Antarctica/Palmer
Atlantic/Bermuda
Atlantic/Stanley
Brazil/West
Canada/Atlantic
Chile/Continental
Etc/GMT+4
PRT
SystemV/AST4
SystemV/AST4ADT
America/St_Johns
CNT
Canada/Newfoundland
AGT
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Jujuy
America/Argentina/La_Rioja
America/Argentina/Mendoza
America/Argentina/Rio_Gallegos
America/Argentina/San_Juan
America/Argentina/Tucuman
America/Argentina/Ushuaia
America/Bahia
America/Belem
America/Buenos_Aires
America/Catamarca
America/Cayenne
America/Cordoba
America/Fortaleza
America/Godthab
America/Jujuy
America/Maceio
America/Mendoza
America/Miquelon
America/Montevideo
America/Paramaribo
America/Recife
America/Rosario
America/Sao_Paulo
Antarctica/Rothera
BET
Brazil/East
Etc/GMT+3
America/Noronha
Atlantic/South_Georgia
Brazil/DeNoronha
Etc/GMT+2
America/Scoresbysund
Atlantic/Azores
Atlantic/Cape_Verde
Etc/GMT+1
Africa/Abidjan
Africa/Accra
Africa/Bamako
Africa/Banjul
Africa/Bissau
Africa/Casablanca
Africa/Conakry
Africa/Dakar
Africa/El_Aaiun
Africa/Freetown
Africa/Lome
Africa/Monrovia
Africa/Nouakchott
Africa/Ouagadougou
Africa/Sao_Tome
Africa/Timbuktu
America/Danmarkshavn
Atlantic/Canary
Atlantic/Faeroe
Atlantic/Faroe
Atlantic/Madeira
Atlantic/Reykjavik
Atlantic/St_Helena
Eire
Etc/GMT
Etc/GMT+0
Etc/GMT-0
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/UTC
Etc/Universal
Etc/Zulu
Europe/Belfast
Europe/Dublin
Europe/Guernsey
Europe/Isle_of_Man
Europe/Jersey
Europe/Lisbon
Europe/London
GB
GB-Eire
GMT
GMT0
Greenwich
Iceland
Portugal
UCT
UTC
Universal
WET
Zulu
Africa/Algiers
Africa/Bangui
Africa/Brazzaville
Africa/Ceuta
Africa/Douala
Africa/Kinshasa
Africa/Lagos
Africa/Libreville
Africa/Luanda
Africa/Malabo
Africa/Ndjamena
Africa/Niamey
Africa/Porto-Novo
Africa/Tunis
Africa/Windhoek
Arctic/Longyearbyen
Atlantic/Jan_Mayen
CET
ECT
Etc/GMT-1
Europe/Amsterdam
Europe/Andorra
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Budapest
Europe/Copenhagen
Europe/Gibraltar
Europe/Ljubljana
Europe/Luxembourg
Europe/Madrid
Europe/Malta
Europe/Monaco
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Rome
Europe/San_Marino
Europe/Sarajevo
Europe/Skopje
Europe/Stockholm
Europe/Tirane
Europe/Vaduz
Europe/Vatican
Europe/Vienna
Europe/Warsaw
Europe/Zagreb
Europe/Zurich
MET
Poland
ART
Africa/Blantyre
Africa/Bujumbura
Africa/Cairo
Africa/Gaborone
Africa/Harare
Africa/Johannesburg
Africa/Kigali
Africa/Lubumbashi
Africa/Lusaka
Africa/Maputo
Africa/Maseru
Africa/Mbabane
Africa/Tripoli
Asia/Amman
Asia/Beirut
Asia/Damascus
Asia/Gaza
Asia/Istanbul
Asia/Jerusalem
Asia/Nicosia
Asia/Tel_Aviv
CAT
EET
Egypt
Etc/GMT-2
Europe/Athens
Europe/Bucharest
Europe/Chisinau
Europe/Helsinki
Europe/Istanbul
Europe/Kaliningrad
Europe/Kiev
Europe/Mariehamn
Europe/Minsk
Europe/Nicosia
Europe/Riga
Europe/Simferopol
Europe/Sofia
Europe/Tallinn
Europe/Tiraspol
Europe/Uzhgorod
Europe/Vilnius
Europe/Zaporozhye
Israel
Libya
Turkey
Africa/Addis_Ababa
Africa/Asmara
Africa/Asmera
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Kampala
Africa/Khartoum
Africa/Mogadishu
Africa/Nairobi
Antarctica/Syowa
Asia/Aden
Asia/Baghdad
Asia/Bahrain
Asia/Kuwait
Asia/Qatar
Asia/Riyadh
EAT
Etc/GMT-3
Europe/Moscow
Europe/Volgograd
Indian/Antananarivo
Indian/Comoro
Indian/Mayotte
W-SU
Asia/Riyadh87
Asia/Riyadh88
Asia/Riyadh89
Mideast/Riyadh87
Mideast/Riyadh88
Mideast/Riyadh89
Asia/Tehran
Iran
Asia/Baku
Asia/Dubai
Asia/Muscat
Asia/Tbilisi
Asia/Yerevan
Etc/GMT-4
Europe/Samara
Indian/Mahe
Indian/Mauritius
Indian/Reunion
NET
Asia/Kabul
Asia/Aqtau
Asia/Aqtobe
Asia/Ashgabat
Asia/Ashkhabad
Asia/Dushanbe
Asia/Karachi
Asia/Oral
Asia/Samarkand
Asia/Tashkent
Asia/Yekaterinburg
Etc/GMT-5
Indian/Kerguelen
Indian/Maldives
PLT
Asia/Calcutta
Asia/Colombo
IST
Asia/Katmandu
Antarctica/Mawson
Antarctica/Vostok
Asia/Almaty
Asia/Bishkek
Asia/Dacca
Asia/Dhaka
Asia/Novosibirsk
Asia/Omsk
Asia/Qyzylorda
Asia/Thimbu
Asia/Thimphu
BST
Etc/GMT-6
Indian/Chagos
Asia/Rangoon
Indian/Cocos
Antarctica/Davis
Asia/Bangkok
Asia/Hovd
Asia/Jakarta
Asia/Krasnoyarsk
Asia/Phnom_Penh
Asia/Pontianak
Asia/Saigon
Asia/Vientiane
Etc/GMT-7
Indian/Christmas
VST
Antarctica/Casey
Asia/Brunei
Asia/Chongqing
Asia/Chungking
Asia/Harbin
Asia/Hong_Kong
Asia/Irkutsk
Asia/Kashgar
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Macao
Asia/Macau
Asia/Makassar
Asia/Manila
Asia/Shanghai
Asia/Singapore
Asia/Taipei
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Australia/Perth
Australia/West
CTT
Etc/GMT-8
Hongkong
PRC
Singapore
Australia/Eucla
Asia/Choibalsan
Asia/Dili
Asia/Jayapura
Asia/Pyongyang
Asia/Seoul
Asia/Tokyo
Asia/Yakutsk
Etc/GMT-9
JST
Japan
Pacific/Palau
ROK
ACT
Australia/Adelaide
Australia/Broken_Hill
Australia/Darwin
Australia/North
Australia/South
Australia/Yancowinna
AET
Antarctica/DumontDUrville
Asia/Sakhalin
Asia/Vladivostok
Australia/ACT
Australia/Brisbane
Australia/Canberra
Australia/Currie
Australia/Hobart
Australia/Lindeman
Australia/Melbourne
Australia/NSW
Australia/Queensland
Australia/Sydney
Australia/Tasmania
Australia/Victoria
Etc/GMT-10
Pacific/Guam
Pacific/Port_Moresby
Pacific/Saipan
Pacific/Truk
Pacific/Yap
Australia/LHI
Australia/Lord_Howe
Asia/Magadan
Etc/GMT-11
Pacific/Efate
Pacific/Guadalcanal
Pacific/Kosrae
Pacific/Noumea
Pacific/Ponape
SST
Pacific/Norfolk
Antarctica/McMurdo
Antarctica/South_Pole
Asia/Anadyr
Asia/Kamchatka
Etc/GMT-12
Kwajalein
NST
NZ
Pacific/Auckland
Pacific/Fiji
Pacific/Funafuti
Pacific/Kwajalein
Pacific/Majuro
Pacific/Nauru
Pacific/Tarawa
Pacific/Wake
Pacific/Wallis
NZ-CHAT
Pacific/Chatham
Etc/GMT-13
Pacific/Enderbury
Pacific/Tongatapu
Etc/GMT-14
Pacific/Kiritimati
America/Indiana/Petersburg
America/Indiana/Vincennes
Current time Thu Mar 27 05:58:58 SGT 2008
From Date - Thursday, March 27, 2008 4:58:58 AM ICT
To Date - Wednesday, March 26, 2008 3:58:58 PM MDT
Program End





No comments: