Results 1 to 4 of 4
  1. #1
    Rocketz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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 02:32 AM.

  4. #4
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default

    Java Code:
    		Calendar cal = Calendar.getInstance();
    		cal.set(2011, Calendar.APRIL, 10, 22, 00, 55);
    		long startDateTime = cal.getTimeInMillis();
    for more info
    Calendar (Java 2 Platform SE v1.4.2)

Similar Threads

  1. Integer.parseInt() error
    By niteangell21 in forum New To Java
    Replies: 4
    Last Post: 02-06-2011, 06:36 AM
  2. Integer.parseInt("5.843"); Error
    By Cemi in forum New To Java
    Replies: 3
    Last Post: 04-15-2010, 06:16 PM
  3. [SOLVED] Integer.parseInt() problem
    By eggmanpete in forum New To Java
    Replies: 18
    Last Post: 02-15-2009, 05:25 PM
  4. Integer.parseInt?
    By Exhonour in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 03:31 AM
  5. Problem with Integer.parseInt()
    By Hevonen in forum New To Java
    Replies: 2
    Last Post: 12-14-2008, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •