Results 1 to 6 of 6

Thread: Oops management Date and TimeZone

  1. #1
    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.

  2. #2
    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    330

    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. #4
    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.

  5. #5
    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.

  6. #6
    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.

Similar Threads

  1. Replies: 5
    Last Post: 07-10-2010, 06:47 AM
  2. Piwigo on SME 7.4: timezone problem
    By Leeland in forum Operating Systems
    Replies: 5
    Last Post: 14-01-2010, 11:35 AM
  3. How to set the timezone on my mobile
    By microam_i in forum Portable Devices
    Replies: 1
    Last Post: 19-06-2009, 11:46 PM
  4. TimeZone for Calendars in MS Project 2007
    By pshetty in forum Windows Software
    Replies: 2
    Last Post: 13-05-2009, 03:54 PM
  5. OOPS Concepts
    By suneel_g in forum Software Development
    Replies: 3
    Last Post: 22-12-2008, 12:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,291,506.70549 seconds with 17 queries