• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Date calculation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date calculation


  • Subject: Re: Date calculation
  • From: Sam Barnum <email@hidden>
  • Date: Fri, 23 Apr 2004 09:15:30 -0700

Calendar cal = Calendar.getInstance(); // cal is set to current date
cal.add(Calendar.YEAR, -1); // subtracts 1 year from the calendar
NSTimestamp oneYearAgo = new NSTimestamp(cal.getTimeInMillis());

On Apr 23, 2004, at 7:21 AM, Jim Pearson wrote:

I tend to work date mechanics like this:

//this already gets me the current date. It also lets the JVM decide the type of Calendar.
Calendar workingCalendar = Calendar.getInstance();
//note that this will give you a date of exactly 365 days ago, not a "year" ago.
//some years are longer.
workingCalendar.add( Calendar.DAY_OF_MONTH, -365 );
//then you can get out the time, date, NSTimestamp, etc. from the calendar...


jimp


-----Original Message----- From: Randall Perry <email@hidden> Sent: Apr 23, 2004 9:54 AM To: email@hidden Subject: Date calculation

Read through the archives to get tips on date calc. The consensus seems to
be to convert NSTimestamp to GregorianCalendar to get accuracy.


I need to find the date 1 year ago and tried this:

    NSTimestamp timestamp = new NSTimestamp();
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(timestamp);
    cal.add( GregorianCalendar.DATE, -365);
    newtime = new NSTimestamp(cal.getTime());


But get a compiler error on line 3: 'identifier expected'

What's the problem?


-- Randall Perry sysTame

Xserve Web Hosting/Co-location
Website Development/Promotion
Mac Consulting/Sales

http://www.systame.com/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Date calculation (From: Jim Pearson <email@hidden>)

  • Prev by Date: Re: SOLVED Question for the Java Gurus
  • Next by Date: Re: Primary Key generation - size limit
  • Previous by thread: Re: Date calculation
  • Next by thread: Re: Date calculation
  • Index(es):
    • Date
    • Thread