|
| |||||||||
| Tags: code management, date, object oriented programming, programming language, timezone, utilities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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()); |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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. |
|
#5
| |||
| |||
| 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. |
|
#6
| |||
| |||
| 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()) ); |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |