Knowledge Walls
John Peter
Pune, Maharashtra, India
How to change TimeZone in Java in Date and Time of How-to-use in Core Java
2634 Views
Hints 
By default in Java takes Local system Timezone. Developer can set default TimeZone in Java using TimeZone Class of java.util package. TimeZone class given interaction to get and set the TimeZone in Java.

Example
TimeZone.setDefault();
TimeZone.getTimeZone();
DefaultTimeZoneInJavaExample
import java.util.Date;
import java.util.TimeZone;

public class DefaultTimeZoneInJavaExample {
    public static void main(String args[]) throws InterruptedException, Exception{
        System.out.println("Before");
        System.out.println(new Date());
        
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        
        System.out.println("After");
        System.out.println(new Date());
    }
}
Output 
Before
Thu Mar 06 10:43:02 IST 2014

After
Thu Mar 06 05:13:02 UTC 2014
Previous Topics
Previous lessons of current book.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details