Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    public static void main(String[] args) {
        // Get the current date in the system default time zone
        GregorianCalendar currentDate = new GregorianCalendar();
        System.out.println(currentDate.getTime());
        // Get GregorianCalendar object representing March 21, 2014 07:30:45 AM
        GregorianCalendar someDate = new GregorianCalendar(2014, Calendar.MARCH, 21, 7, 30, 45);
        System.out.println(someDate.getTime());
        // Get Indian time zone, which is GMT+05:30
        TimeZone indianTZ = TimeZone.getTimeZone("GMT+05:30");
        GregorianCalendar indianDate = new GregorianCalendar(indianTZ);
        System.out.println(indianDate.getTime());
    }

}