Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Oops management Date and TimeZone

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 204
Oops management Date and TimeZone

Hello,
I must make comparisons of dates, but it becomes more difficult when I want to change the TimeZone. I hope that people a little more experienced in this area will address this thorny problem. Here is my code, just go through it.
Code:
Calendar c1 = Calendar.getInstance(TZ1);
c1.set(_year, _MONTH, _DAY, _HOUR, _minute, Seconds);
Date d1 = c1.getTime();

Calendar c2 = Calendar.getInstance(TZ2);
c2.set(_year, _MONTH, _DAY, _HOUR, _minute, Seconds);
Date date2 = c2.getTime();

System.out.System.out.println("1 - d1" + Date1 + "(Calendar.HOUR" + Cal1.get(Calendar.HOUR_OF_DAY) + " - " + Cal1.getTimeInMillis() + ")");
System.out.System.out.println("2 - date2" + Date2 + "(Calendar.HOUR" + c2.get(Calendar.HOUR_OF_DAY) + " - " + c2.getTimeInMillis() + ")");
System.out.System.out.println("3 - Comparison: + (d1.getTime() == Date2.getTime()) + "-> Wait: false");
System.out.System.out.println("4 - TimeZone:" + Cal1.getTimezone().getDisplayName() + "And" + c2.getTimezone().getDisplayName());
I have no idea how it is not working for me. I want to know how to manage the date and the time in the OOP's. If you have any ideas or any documentation on this then please do post back.
Reply With Quote
  #2  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: Oops management Date and TimeZone

Hello,
Even I have same problem with my program, but the problem is that the context is different. At this project, I can not add new API. So I have to make do with what I have (ie Calendar, Date and TimeZone) Would anyone else have any ideas? Or if you have any other alternative for this then you can suggest me that. Thanks in advance.
Reply With Quote
  #3  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 331
Re: Oops management Date and TimeZone

Hello,
I think you are confused in this, 11am to GMT 0 is indeed different from 11am GMT on 2. You can do nothing against that. If you want to ignore the concept of "timezone", ensures you always be in the same timezone in the construction of your dates. I think you should clear this concept and then move forward for doing the coding part. If you want to know more about it then you can visit the sun java API.
Reply With Quote
  #4  
Old 09-02-2010
Member
 
Join Date: Dec 2009
Posts: 204
Re: Oops management Date and TimeZone

Hello,
Thanks for you reply. Precisely, it is the whole problem. We are in complete agreement, 11H in GMT +0 GMT +2, it is beautiful and very different. But, a prior, Java is not entirely agreed with this condition That's the whole world problem of time zone, because obviously I have to work with the TimeZone. Otherwise there is no use in using this method.
Reply With Quote
  #5  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Oops management Date and TimeZone

Hello,
I do not understand your problem too. To me everything seems logical. In the first case, you create two dates in two different time zones (same years / months / days / etc. But different time zones), then you have two objects very different dates. In the latter two dates you create exactly the same (same info and same time - the default). Changing the time zone later does not change the date value but only its display.
Reply With Quote
  #6  
Old 09-02-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Oops management Date and TimeZone

Hello,
I think i have a solution for this, the solution is to use DateFormat and specify the timezone before each display, just have a look at the following code.
Code:
	DateFormat d = DateFormat.getDateTimeInstance();

d.setTimezone(c1.getTimezone());
System.out.System.out.println( d.format(c1.getTime()) );

d.setTimezone(c2.getTimezone());
System.out.System.out.println( d.format(c2.getTime()) );
Hope this code works for you. Best of Luck.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Oops management Date and TimeZone"
Thread Thread Starter Forum Replies Last Post
Piwigo on SME 7.4: timezone problem Leeland Operating Systems 5 14-01-2010 11:35 AM
Windows keeps reverting to wrong timezone acp73 Windows XP Support 3 06-07-2009 04:32 PM
How to set the timezone on my mobile microam_i Portable Devices 1 20-06-2009 12:46 AM
TimeZone for Calendars in MS Project 2007 pshetty Windows Software 2 13-05-2009 04:54 PM
OOPS Concepts suneel_g Software Development 3 22-12-2008 12:42 PM


All times are GMT +5.5. The time now is 04:23 AM.