11, మే 2012, శుక్రవారం

USING THE CODE BELOW YOU CAN GET A LIST OF COUNTRY NAMES AND ITS ISO CODE BY USING THE LOCALE CLASS IMPLEMENTATION IN JAVA.


import java.util.*;
import java.text.*;
public class mydate
{
public static void main(String args[])
{

Date d=new Date();
DateFormat fmt= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.JAPAN);
System.out.println("JAPAN FORMAT "+fmt.format(d));

DateFormat fmt1= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.GERMANY);
System.out.println("GERMANY FORMAT "+fmt1.format(d));


DateFormat fmt2= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.CHINA);
System.out.println("CHINA FORMAT "+fmt2.format(d));

DateFormat fmt3= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.CANADA);
System.out.println("CANADA FORMAT "+fmt3.format(d));


DateFormat fmt4= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.FRANCE);
System.out.println("FRANCE FORMAT "+fmt4.format(d));


DateFormat fmt5= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.US);
System.out.println("UNITED STATES FORMAT "+fmt5.format(d));


DateFormat fmt6= DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.UK);
System.out.println("UNITED KINGDOM FORMAT "+fmt6.format(d));


}
}
E:\jit1>javac mydate.java

E:\jit1>java mydate
JAPAN FORMAT 2012/05/29 14:57:41
GERMANY FORMAT 29.05.2012 14:57:41
CHINA FORMAT 2012-5-29 14:57:41
CANADA FORMAT 29-May-2012 2:57:41 PM
FRANCE FORMAT 29 mai 2012 14:57:41
UNITED STATES FORMAT May 29, 2012 2:57:41 PM
UNITED KINGDOM FORMAT 29-May-2012 14:57:41
Using the code below you can get a list of country names and its ISO code by using the locale class implementation in Java.
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

public class CountryList {
    public static void main(String[] args) {
        // A collection to store our country object
     
        List<Country> countries = new ArrayList<Country>();

     
        // Get ISO countries, create Country object an store in the collection.
       
        String[] isoCountries = Locale.getISOCountries();
        for (String country : isoCountries) {
            Locale locale = new Locale("en", country);
            String iso = locale.getISO3Country();
            String code = locale.getCountry();
            String name = locale.getDisplayCountry();

            if (!"".equals(iso) && !"".equals(code)
                    && !"".equals(name)) {
                countries.add(new Country(iso, code, name));
            }
        }

       
        // Sort the country by their name and then display the content of countries collection object.
       
        Collections.sort(countries, new CountryComparator());

        for (Country country : countries) {
            System.out.println(country);
        }
    }

    /*Country pojo class.*/
    static class Country {
        private String iso;
        private String code;
        private String name;

        Country(String iso, String code, String name) {
            this.iso = iso;
            this.code = code;
            this.name = name;
        }

        public String toString() {
            return iso + " - " + code + " - " + name.toUpperCase();
        }
    }

    /* CountryComparator class*/
    static class CountryComparator implements Comparator<Country> {
        private Comparator comparator;

        CountryComparator() {
            comparator = Collator.getInstance();
        }

        @SuppressWarnings("unchecked")
        public int compare(Country c1, Country c2) {
            return comparator.compare(c1.name, c2.name);
        }
    }
}
E:\jit1>javac CountryList.java
Note: CountryList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

E:\jit1>java CountryList
AFG - AF - AFGHANISTAN
ALA - AX - LAND ISLANDS
ALB - AL - ALBANIA
DZA - DZ - ALGERIA
ASM - AS - AMERICAN SAMOA
AND - AD - ANDORRA
AGO - AO - ANGOLA
AIA - AI - ANGUILLA
ATA - AQ - ANTARCTICA
ATG - AG - ANTIGUA AND BARBUDA
ARG - AR - ARGENTINA
ARM - AM - ARMENIA
ABW - AW - ARUBA
AUS - AU - AUSTRALIA
AUT - AT - AUSTRIA
AZE - AZ - AZERBAIJAN
BHS - BS - BAHAMAS
BHR - BH - BAHRAIN
BGD - BD - BANGLADESH
BRB - BB - BARBADOS
BLR - BY - BELARUS
BEL - BE - BELGIUM
BLZ - BZ - BELIZE
BEN - BJ - BENIN
BMU - BM - BERMUDA
BTN - BT - BHUTAN
BOL - BO - BOLIVIA
BIH - BA - BOSNIA AND HERZEGOVINA
BWA - BW - BOTSWANA
BVT - BV - BOUVET ISLAND
BRA - BR - BRAZIL
IOT - IO - BRITISH INDIAN OCEAN TERRITORY
VGB - VG - BRITISH VIRGIN ISLANDS
BRN - BN - BRUNEI
BGR - BG - BULGARIA
BFA - BF - BURKINA FASO
BDI - BI - BURUNDI
KHM - KH - CAMBODIA
CMR - CM - CAMEROON
CAN - CA - CANADA
CPV - CV - CAPE VERDE
CYM - KY - CAYMAN ISLANDS
CAF - CF - CENTRAL AFRICAN REPUBLIC
TCD - TD - CHAD
CHL - CL - CHILE
CHN - CN - CHINA
CXR - CX - CHRISTMAS ISLAND
CCK - CC - COCOS ISLANDS
COL - CO - COLOMBIA
COM - KM - COMOROS
COG - CG - CONGO
COK - CK - COOK ISLANDS
CRI - CR - COSTA RICA
CIV - CI - CTE D'IVOIRE
HRV - HR - CROATIA
CUB - CU - CUBA
CYP - CY - CYPRUS
CZE - CZ - CZECH REPUBLIC
DNK - DK - DENMARK
DJI - DJ - DJIBOUTI
DMA - DM - DOMINICA
DOM - DO - DOMINICAN REPUBLIC
ECU - EC - ECUADOR
EGY - EG - EGYPT
SLV - SV - EL SALVADOR
GNQ - GQ - EQUATORIAL GUINEA
ERI - ER - ERITREA
EST - EE - ESTONIA
ETH - ET - ETHIOPIA
FLK - FK - FALKLAND ISLANDS
FRO - FO - FAROE ISLANDS
FJI - FJ - FIJI
FIN - FI - FINLAND
FRA - FR - FRANCE
GUF - GF - FRENCH GUIANA
PYF - PF - FRENCH POLYNESIA
ATF - TF - FRENCH SOUTHERN TERRITORIES
GAB - GA - GABON
GMB - GM - GAMBIA
GEO - GE - GEORGIA
DEU - DE - GERMANY
GHA - GH - GHANA
GIB - GI - GIBRALTAR
GRC - GR - GREECE
GRL - GL - GREENLAND
GRD - GD - GRENADA
GLP - GP - GUADELOUPE
GUM - GU - GUAM
GTM - GT - GUATEMALA
GGY - GG - GUERNSEY
GIN - GN - GUINEA
GNB - GW - GUINEA-BISSAU
GUY - GY - GUYANA
HTI - HT - HAITI
HMD - HM - HEARD ISLAND AND MCDONALD ISLANDS
HND - HN - HONDURAS
HKG - HK - HONG KONG
HUN - HU - HUNGARY
ISL - IS - ICELAND
IND - IN - INDIA
IDN - ID - INDONESIA
IRN - IR - IRAN
IRQ - IQ - IRAQ
IRL - IE - IRELAND
IMN - IM - ISLE OF MAN
ISR - IL - ISRAEL
ITA - IT - ITALY
JAM - JM - JAMAICA
JPN - JP - JAPAN
JEY - JE - JERSEY
JOR - JO - JORDAN
KAZ - KZ - KAZAKHSTAN
KEN - KE - KENYA
KIR - KI - KIRIBATI
KWT - KW - KUWAIT
KGZ - KG - KYRGYZSTAN
LAO - LA - LAOS
LVA - LV - LATVIA
LBN - LB - LEBANON
LSO - LS - LESOTHO
LBR - LR - LIBERIA
LBY - LY - LIBYA
LIE - LI - LIECHTENSTEIN
LTU - LT - LITHUANIA
LUX - LU - LUXEMBOURG
MAC - MO - MACAO
MKD - MK - MACEDONIA
MDG - MG - MADAGASCAR
MWI - MW - MALAWI
MYS - MY - MALAYSIA
MDV - MV - MALDIVES
MLI - ML - MALI
MLT - MT - MALTA
MHL - MH - MARSHALL ISLANDS
MTQ - MQ - MARTINIQUE
MRT - MR - MAURITANIA
MUS - MU - MAURITIUS
MYT - YT - MAYOTTE
MEX - MX - MEXICO
FSM - FM - MICRONESIA
MDA - MD - MOLDOVA
MCO - MC - MONACO
MNG - MN - MONGOLIA
MNE - ME - MONTENEGRO
MSR - MS - MONTSERRAT
MAR - MA - MOROCCO
MOZ - MZ - MOZAMBIQUE
MMR - MM - MYANMAR
NAM - NA - NAMIBIA
NRU - NR - NAURU
NPL - NP - NEPAL
NLD - NL - NETHERLANDS
ANT - AN - NETHERLANDS ANTILLES
NCL - NC - NEW CALEDONIA
NZL - NZ - NEW ZEALAND
NIC - NI - NICARAGUA
NER - NE - NIGER
NGA - NG - NIGERIA
NIU - NU - NIUE
NFK - NF - NORFOLK ISLAND
MNP - MP - NORTHERN MARIANA ISLANDS
PRK - KP - NORTH KOREA
NOR - NO - NORWAY
OMN - OM - OMAN
PAK - PK - PAKISTAN
PLW - PW - PALAU
PSE - PS - PALESTINE
PAN - PA - PANAMA
PNG - PG - PAPUA NEW GUINEA
PRY - PY - PARAGUAY
PER - PE - PERU
PHL - PH - PHILIPPINES
PCN - PN - PITCAIRN
POL - PL - POLAND
PRT - PT - PORTUGAL
PRI - PR - PUERTO RICO
QAT - QA - QATAR
REU - RE - REUNION
ROU - RO - ROMANIA
RUS - RU - RUSSIA
RWA - RW - RWANDA
BLM - BL - SAINT BARTHLEMY
SHN - SH - SAINT HELENA
KNA - KN - SAINT KITTS AND NEVIS
LCA - LC - SAINT LUCIA
MAF - MF - SAINT MARTIN
SPM - PM - SAINT PIERRE AND MIQUELON
VCT - VC - SAINT VINCENT AND THE GRENADINES
WSM - WS - SAMOA
SMR - SM - SAN MARINO
STP - ST - SAO TOME AND PRINCIPE
SAU - SA - SAUDI ARABIA
SEN - SN - SENEGAL
SRB - RS - SERBIA
SCG - CS - SERBIA AND MONTENEGRO
SYC - SC - SEYCHELLES
SLE - SL - SIERRA LEONE
SGP - SG - SINGAPORE
SVK - SK - SLOVAKIA
SVN - SI - SLOVENIA
SLB - SB - SOLOMON ISLANDS
SOM - SO - SOMALIA
ZAF - ZA - SOUTH AFRICA
SGS - GS - SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS
KOR - KR - SOUTH KOREA
ESP - ES - SPAIN
LKA - LK - SRI LANKA
SDN - SD - SUDAN
SUR - SR - SURINAME
SJM - SJ - SVALBARD AND JAN MAYEN
SWZ - SZ - SWAZILAND
SWE - SE - SWEDEN
CHE - CH - SWITZERLAND
SYR - SY - SYRIA
TWN - TW - TAIWAN
TJK - TJ - TAJIKISTAN
TZA - TZ - TANZANIA
THA - TH - THAILAND
COD - CD - THE DEMOCRATIC REPUBLIC OF CONGO
TLS - TL - TIMOR-LESTE
TGO - TG - TOGO
TKL - TK - TOKELAU
TON - TO - TONGA
TTO - TT - TRINIDAD AND TOBAGO
TUN - TN - TUNISIA
TUR - TR - TURKEY
TKM - TM - TURKMENISTAN
TCA - TC - TURKS AND CAICOS ISLANDS
TUV - TV - TUVALU
VIR - VI - U.S. VIRGIN ISLANDS
UGA - UG - UGANDA
UKR - UA - UKRAINE
ARE - AE - UNITED ARAB EMIRATES
GBR - GB - UNITED KINGDOM
USA - US - UNITED STATES
UMI - UM - UNITED STATES MINOR OUTLYING ISLANDS
URY - UY - URUGUAY
UZB - UZ - UZBEKISTAN
VUT - VU - VANUATU
VAT - VA - VATICAN
VEN - VE - VENEZUELA
VNM - VN - VIETNAM
WLF - WF - WALLIS AND FUTUNA
ESH - EH - WESTERN SAHARA
YEM - YE - YEMEN
ZMB - ZM - ZAMBIA
ZWE - ZW - ZIMBABWE

E:\jit1>

import java.util.*;
class caldemo
{
public static void main(String args[])
{
Calendar c= Calendar.getInstance();
System.out.println(c);
System.out.println(c.get(Calendar.DATE)+","+c.get(Calendar.MONTH)+","+c.get(Calendar.YEAR)+","
+c.get(Calendar.HOUR)+","+c.get(Calendar.MINUTE)+","+c.get(Calendar.SECOND));
Suppose if u know the difference between the us and India than you add that time to this time and set to the cal or directly print it

// in this example u can do so addition of the time and set to the different country time to u r application if u are developing the application for the other timing zones
}
}
output:-
E:\jit1>javac caldemo.java

E:\jit1>java caldemo
java.util.GregorianCalendar[time=1338285625497,areFieldsSet=true,areAllFieldsSet
=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=198
00000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek
=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2012,MONTH=4,WEEK_OF_YEAR=22,WEEK_OF_MONT
H=5,DAY_OF_MONTH=29,DAY_OF_YEAR=150,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1
,HOUR=3,HOUR_OF_DAY=15,MINUTE=30,SECOND=25,MILLISECOND=497,ZONE_OFFSET=19800000,
DST_OFFSET=0]
29-4-2012  3.30.25
 

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి