File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Time zones program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Time zones program" Watch "Time zones program" New topic

Time zones program

Rebecca Plumb

Joined: Dec 09, 2007
Posts: 9

I need to create a program that that uses a superclass to get the time for 3 cities, using the Millisec method. Not sure how to get the tinme difference for each city:

import static java.lang.System.out;

import java.util.Calendar;
import java.util.Date;

public class WorldTime {

static int DAY_IM = 3 * 60 * 60 * 1000;

public static void main (String [] args){

WorldTime time [] = new WorldTime [3];

time[0] = new MunichTime();
time[1] = new NewYorkTime();
time[2] = new SydneyTime();

Calendar c = Calendar.getInstance();

c.set(2008, 2, 18);

long day1 = c.getTimeInMillis();


out.println(String.format("Time:" , c));

public class MunichTime extends WorldTime {


public class NewYorkTime extends WorldTime {


public class SydneyTime extends WorldTime {


Deepak Chopra
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Ok, I give you one something, This might help you,
no matter in which country I am, Following code will calculate current time in New York:

The main point to note down is First we need to calculate the GMT and I know the New York is GMT - 5.
Following URL will help you find out GMT of every place :
GMT difference

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
I agree. Here's the link:
subject: Time zones program
It's not a secret anymore!