Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    3
    Rep Power
    0

    Default Creating a Gregorian Calendar using a Date object gives date - 1

    I have a Date object
    Date dt = rs.getDate("passwordExpiryDate"); // This returns me date as 10 May 2008
    now I want to check if today is my password expiry date -
    TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT-0");
    Calendar calendarExp =new GregorianCalendar(TIME_ZONE); // This gives me todays date i.e. 8 May 2008
    calendarExp.setTime(dt);
    When I set dt to the calendar it changes the date to 7 May 2008.

    Can any onw pls help me..

    Thanks,
    Prachi

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.text.*;
    import java.util.*;
    
    public class Test {
        public static void main(String[] args) {
            DateFormat df = new SimpleDateFormat("HHmm dd MMM yyyy");
            TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT-0");
            System.out.println("TIME_ZONE = " + TIME_ZONE.getID());
            Calendar calendar = Calendar.getInstance();
            System.out.println("local TZ = " + calendar.getTimeZone().getID());
            calendar.set(2008, 04, 10, 24, 00);  // midnight gmt
            Date expDate = calendar.getTime();
            System.out.printf("expDate    = %s%n", df.format(expDate));
    
            Calendar gmtCalendar = Calendar.getInstance();
            calendar.setTimeZone(TIME_ZONE);
            gmtCalendar.setTime(expDate);
            Date gmtExpDate = gmtCalendar.getTime();
            System.out.printf("gmtExpDate = %s%n", df.format(gmtExpDate));
    
            Calendar calendarExp = new GregorianCalendar(TIME_ZONE);
            calendarExp.setTime(expDate);
            System.out.printf("calExpDate = %s%n", df.format(calendarExp.getTime()));
        }
    }

Similar Threads

  1. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  2. java Date and Calendar
    By valoyivd in forum New To Java
    Replies: 1
    Last Post: 03-30-2008, 06:49 PM
  3. Calendar.DATE
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-04-2008, 07:51 PM
  4. File creating date/time
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 07:43 PM
  5. Help with gregorian calendar
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •