Jan 31, 2005 #1 beanNut IS-IT--Management Joined Jun 2, 2004 Messages 28 Location US Can someone provide a snippet for calculating Tomorrow and also Yesterday? Having trouble with this - not as simple as I thought??
Can someone provide a snippet for calculating Tomorrow and also Yesterday? Having trouble with this - not as simple as I thought??
Feb 1, 2005 #2 Diancecht Programmer Joined Jan 8, 2004 Messages 4,042 Location ES What did you try so far? There must be easier and more accurate ways, that look at Calendar class, for instance, but I can think on this: Code: long oneDay = (long) 1000.0 * 60 * 60 * 24; java.util.Date tomorrow = new java.util.Date(System.currentTimeMillis()+oneDay); java.util.Date today = new java.util.Date(System.currentTimeMillis()); java.util.Date yesterday = new java.util.Date(System.currentTimeMillis()-oneDay); Btw, I think the roght forum to post this is the Java forum. Cheers, Dian Upvote 0 Downvote
What did you try so far? There must be easier and more accurate ways, that look at Calendar class, for instance, but I can think on this: Code: long oneDay = (long) 1000.0 * 60 * 60 * 24; java.util.Date tomorrow = new java.util.Date(System.currentTimeMillis()+oneDay); java.util.Date today = new java.util.Date(System.currentTimeMillis()); java.util.Date yesterday = new java.util.Date(System.currentTimeMillis()-oneDay); Btw, I think the roght forum to post this is the Java forum. Cheers, Dian
Feb 2, 2005 #3 timw Programmer Joined May 3, 2000 Messages 1,264 Location GB You could do something like:- Code: Calendar cal1 = Calendar.getInstance(); cal1.add(Calendar.DATE, 1); //For tomorrow Calendar cal2 = Calendar.getInstance(); cal2.add(Calendar.DATE, -1); //For yesterday Tim Upvote 0 Downvote
You could do something like:- Code: Calendar cal1 = Calendar.getInstance(); cal1.add(Calendar.DATE, 1); //For tomorrow Calendar cal2 = Calendar.getInstance(); cal2.add(Calendar.DATE, -1); //For yesterday Tim