Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008, 10:24 AM
Member
 
Join Date: Apr 2008
Posts: 2
prachi_goliwadekar is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-08-2008, 09:32 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
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())); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between current date and anothe date vijay balusamy New To Java 1 04-16-2008 05:15 PM
java Date and Calendar valoyivd New To Java 1 03-30-2008 07:49 PM
Calendar.DATE mew New To Java 1 01-04-2008 08:51 PM
File creating date/time bugger New To Java 1 11-11-2007 08:43 PM
Help with gregorian calendar osval New To Java 2 08-07-2007 12:21 AM


All times are GMT +3. The time now is 04:31 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org