Results 1 to 2 of 2
- 05-08-2008, 09:24 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 3
- Rep Power
- 0
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
- 05-08-2008, 08:32 PM #2
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
-
Difference between current date and anothe date
By vijay balusamy in forum New To JavaReplies: 1Last Post: 04-16-2008, 04:15 PM -
java Date and Calendar
By valoyivd in forum New To JavaReplies: 1Last Post: 03-30-2008, 06:49 PM -
Calendar.DATE
By mew in forum New To JavaReplies: 1Last Post: 01-04-2008, 07:51 PM -
File creating date/time
By bugger in forum New To JavaReplies: 1Last Post: 11-11-2007, 07:43 PM -
Help with gregorian calendar
By osval in forum New To JavaReplies: 2Last Post: 08-06-2007, 11:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks