|
Robert, The Calendar class is contrived and there are better packages available, but here is something to get you started: package tests; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; /** * @author dmorris * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class DateDifference { static final int MILLIS_PER_DAY = 24 * 60 * 60 * 1000; public static void main(String[] args) { // Input date. TimeZone mst = TimeZone.getTimeZone("America/Denver"); GregorianCalendar birthday = new GregorianCalendar(mst); birthday.set(2002, Calendar.OCTOBER, 29, 12, 0, 0); // now is current time GregorianCalendar now = new GregorianCalendar(mst); // milliseconds since 1970 Jan 1 long epochBirthday = birthday.getTime().getTime(); long epochNow = now.getTime().getTime(); double hours = (double)(epochBirthday - epochNow) / MILLIS_PER_DAY; System.out.println(hours + " days until my next birthday."); GregorianCalendar dayAfter = new GregorianCalendar(mst); dayAfter.set(2002, Calendar.OCTOBER, 29, 12, 0, 0); dayAfter.add(Calendar.DATE, 1); SimpleDateFormat sdf = new SimpleDateFormat("EEEE yyyy/MM/dd hh:mm:ss aa zz : zzzzzz"); sdf.setCalendar(dayAfter); System.out.println("The day after is: " + sdf.format(dayAfter.getTime())); } } You definately want to encapsulate this in something useful. David Morris >>> rupshall@psasoft.com 07/18/02 07:27AM >>> Does java have any date classes that will allow me to do date calculation like the date type in RPG? ie. newDate = date.addDay(1) ; Robert _______________________________________________ This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list To post a message email: JAVA400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l or email: JAVA400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/java400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.