Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with date

Status
Not open for further replies.

zeevgetner

Programmer
Dec 24, 2000
37
IL
hi everybody,

i want to get the system time.
as simple as it sounds it doesnt work.
im using the following code:

TimeZone tz = TimeZone.getTimeZone("Asia/Tel_Aviv");
Calendar c = Calendar.getInstance(tz);
formatter.setTimeZone(tz);
myDate = (formatter.format(c.getTime().getTime()));

what ever i try, i keep getting an hour after my real hour.
in some computers im getting the corect hour and in some am not.

what is the problem
 
Humm, so Tel Aviv is not in Europe but Maccabi plays European basket league :p

Maybe it has to do with the date itself, do you get the hour changed in summer?

Cheers,
Dian
 
Here is a tutorial on internationalisation


But if you just want to get the time you can simply do this: -

//*******************
long time = System.currentTimeMillis();

Date d = new Date( time );

String theTimeNow = d.toString();
//*******************

You can use SimpleDateFormat to output the date in the way you want it formatted.

There are other ways to get the time/date but this is handy enough.
 
JNameNotTaken , thank you but your suggestion didnt work,
i still get one hour after my real hour.

dian,

i dont understand exactly what you are saying.
i think that you have a point that it has something to do with the summer time, but i dont know how.

in israel it is now a summer time.
im not sure i know how to define it in windows.

about mackaby, they are the greatest (see you at the sports forume :)
 
Assumming you're using windows, there's an option to automatically adjust hour to dayligth saving changes. Maybe the failing computers don't have it activated.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top