Results 1 to 3 of 3
Thread: Setting a Date?
- 02-24-2011, 07:13 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Setting a Date?
Hey guys. Trying to convert a .NET project to Java here. Here's basically what my program does:
So basically, I have a date/time stored into a variable, and I want to keep adding 7 minutes until that date/time is in the future (past current time).Java Code:Date old = new Date("2/23/2011 12:04:53 PM"); Date now = Date.getNow(); while(old < now) old = old.addMinutes(7);
Any help is greatly appreciated.
- 02-24-2011, 08:37 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Calendar has a set(int field,int value) method which will allow you to update Calendar.MINUTE by whatever the value specified. Date has boolean methods for comparing two Date's i.e. before(Date d) and after(Date d). This should be enough to point you in the right direction
- 02-24-2011, 09:40 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Here's my C# code:
I need someone to convert this to Java.Java Code:DateTime next = DateTime.Parse("2/23/2011 12:04:53 PM"); while (next < DateTime.Now) next = next.AddMinutes(7); Console.Write("Next time: " + next);
Edit: Managed to get something working:If it can be improved, please tell me!Java Code:private static Date getDate() throws ParseException { DateFormat format = new SimpleDateFormat("MM/dd/yyyy h:m:s a"); Date next = format.parse("2/23/2011 12:04:53 PM"); while(next.before(Calendar.getInstance().getTime())) next.setTime(next.getTime() + 420000); return next; }Last edited by Zachafer; 02-24-2011 at 09:49 PM.
Similar Threads
-
converting string (GMT date) to date in US time.
By JRuyechan in forum New To JavaReplies: 1Last Post: 10-15-2010, 07:07 AM -
julian date to full date format
By judy318 in forum New To JavaReplies: 7Last Post: 11-02-2009, 12:17 PM -
Compare date input to database with current date
By hungleon88 in forum Advanced JavaReplies: 2Last Post: 11-25-2008, 08:10 AM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
Difference between current date and anothe date
By vijay balusamy in forum New To JavaReplies: 1Last Post: 04-16-2008, 04:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks