Lets see how java uses the Timezone set on JVM. Lets print the current time and date of the existing time zone.
And then change the time zone to different time zone and observe the changes.
The below code will do the above purpose.
So by observing the output and code lines we can understand that the time changes according to Timezone used.
And then change the time zone to different time zone and observe the changes.
The below code will do the above purpose.
public void testMain(Object[] args)Corresponding output is as follows :
{
Date dt = new Date();
System.out.println("Todays Date and time:"+dt);
Calendar c = Calendar.getInstance();
System.out.println("Current System timeZone : "+c.getTimeZone());
System.out.println("current time : "+c.getTime());
System.out.println("Current time in millis : "+c.getTimeInMillis());
//Lets change the JVM time zone and see
TimeZone cst = TimeZone.getTimeZone("CST");
cst.setDefault(cst);
System.out.println("new time zone: "+cst);
Calendar curCal=Calendar.getInstance(cst);
//System.out.println("New time Zone : "+curCal.getTimeZone());
System.out.println("New time with : "+curCal.getTime());
System.out.println("New Time in millis: " +curCal.getTimeInMillis());
//Some other time operations
Timestamp timeNow = new Timestamp(curCal.getTimeInMillis());
System.out.println("Time stamp type of timeNow= " + timeNow);
sleep(10);
//After some time
c = Calendar.getInstance();
System.out.println("Current timeZone : "+c.getTimeZone());
System.out.println("current time : "+c.getTime());
System.out.println("current time in millis : "+c.getTimeInMillis());
//To pass the current local time format and display like that
SimpleDateFormat DF = new SimpleDateFormat();
System.out.println("Current sys time format : "+ DF.format(c.getTime()));
SimpleDateFormat DF1 = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
System.out.println("Change the Current sys time format : "+ DF1.format(c.getTime()));
}
Todays Date and time:Thu Mar 11 12:21:59 IST 2010Explanation:
Current System timeZone : sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null]
current time : Wed Mar 03 15:47:38 IST 2010
Current time in millis : 1267611458390
new time zone: sun.util.calendar.ZoneInfo[id="CST",offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=CST,offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
New time with : Wed Mar 03 04:17:38 CST 2010
New Time in millis: 1267611458406
Time stamp type of timeNow= {SysUpTime = 146714 days 6:56:24} {Timestamp = Wed Mar 03 04:17:38 CST 2010}
Current timeZone : sun.util.calendar.ZoneInfo[id="CST",offset=-21600000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=CST,offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
current time : Wed Mar 03 04:17:48 CST 2010
current time in millis : 1267611468406
Current sys time format : 3/3/10 4:17 AM
Change the Current sys time format : 2010-03-03 04.17.48
So by observing the output and code lines we can understand that the time changes according to Timezone used.
Wednesday, March 03, 2010
//
Labels:
Java
//
0
comments
//
0 comments to "print the time,date and time zone in java program and change the time zone"
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs
Buffs ...
Tags
Powered by WidgetsForFree
Archives
-
▼
2010
(35)
-
▼
March
(7)
- Automatically start Websphere after system reboot ...
- String comparision in Jython script class exceptio...
- WSVR0009E: Error occurred during startup Cannot ge...
- print the time,date and time zone in java program ...
- How to find Websphere Version in python/jython scr...
- Big Banyan Tree,Srirangapatnam,Balmuri-Edmuri Fall...
- Modelart R/C Helicopter-For indoor flight-3Channel...
-
▼
March
(7)
Post a Comment
Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")