Results 1 to 4 of 4
- 02-27-2011, 12:25 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
Working with Integer parseInt(String)
So I'm working on a method to verify if two dates/times are in chronological order. I'm able to convert the yyyymmdd string into an int but when I use string addition to add on hhmm for the time it fails. Here's what I'm doing
[works]
int startDateTime = Integer.parseInt("yyyymmdd");
[fails]
int startDateTime = Integer.parseInt("yyyymmddhhmm");
Where:
yyyy = 4 digit year
mm = 2 digit month
dd = 2 digit day
hh = 2 digit hour
mm = 2 digit minute
-
Don't do this with ints, but use Date objects -- that's what it's for. You can convert the String to a Date using a SimpleDateFormat object. Then it's trivial to see how one Date compares with another.
- 02-27-2011, 01:29 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Or compare the strings as strings! This is fine for either "yyyymmdd", "yyyymmddhhmm", "yyyymmdd:hhmmss.mmm" etc - provided a fixed number of digits is always present. That's the value of formats that proceed most significant to least significant like that.
Last edited by pbrockway2; 02-27-2011 at 01:32 AM.
- 02-27-2011, 07:31 AM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102
- Rep Power
- 0
for more infoJava Code:Calendar cal = Calendar.getInstance(); cal.set(2011, Calendar.APRIL, 10, 22, 00, 55); long startDateTime = cal.getTimeInMillis();
Calendar (Java 2 Platform SE v1.4.2)
Similar Threads
-
Integer.parseInt() error
By niteangell21 in forum New To JavaReplies: 4Last Post: 02-06-2011, 05:36 AM -
Integer.parseInt("5.843"); Error
By Cemi in forum New To JavaReplies: 3Last Post: 04-15-2010, 05:16 PM -
[SOLVED] Integer.parseInt() problem
By eggmanpete in forum New To JavaReplies: 18Last Post: 02-15-2009, 04:25 PM -
Integer.parseInt?
By Exhonour in forum New To JavaReplies: 4Last Post: 01-20-2009, 02:31 AM -
Problem with Integer.parseInt()
By Hevonen in forum New To JavaReplies: 2Last Post: 12-14-2008, 03:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks