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 07-23-2007, 07:30 PM
Member
 
Join Date: Jul 2007
Posts: 26
osval is on a distinguished road
Help with gregorian calendar
I'm trying to calculate how many days left in the year but it doesn't work

this is my code:
Code:
public class Calculate { public static void main (String args[]) { GregorianCalendar today = new GregorianCalendar(); GregorianCalendar nyear = new GregorianCalendar(365,12,31); long daysleft= nyear .get(nyear .DAY_OF_YEAR) - today.get(today.DAY_OF_YEAR); System.out.println( daysleft); } }
thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 09:59 PM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
maybe here is the answer
Java J2EE Tutorials
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 12:21 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,145
hardwired is on a distinguished road
Code:
DateFormat df = new SimpleDateFormat("ddMMMyyyy"); Calendar today = Calendar.getInstance(); System.out.println("today = " + df.format(today.getTime())); Calendar endOfYear = Calendar.getInstance(); endOfYear.set(2007, 11, 31); System.out.println("endOfYear = " + df.format(endOfYear.getTime())); int daysRemaining = endOfYear.get(Calendar.DAY_OF_YEAR) - today.get(Calendar.DAY_OF_YEAR); System.out.println("days remaining = " + daysRemaining); GregorianCalendar start = new GregorianCalendar(); GregorianCalendar end = new GregorianCalendar(2007, 11, 31); long daysLeft = end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR); System.out.println("daysLeft = " + daysLeft);
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
calendar John SWT / JFace 12 08-07-2008 11:54 PM
How to use Calendar class JavaBean Java Tips 1 06-26-2008 04:09 PM
Calendar.DATE mew New To Java 1 01-04-2008 08:51 PM
Web calendar Daniel Enterprise JavaBeans 1 06-27-2007 06:36 PM
Gregorian calendar issue orchid New To Java 1 05-16-2007 07:51 PM


All times are GMT +3. The time now is 09:56 AM.


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