Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-19-2007, 02:03 AM
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
Parsing Dates for Comparison
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // Get Date 1 try { Date d1 = df.parse("2000-02-01"); } catch(java.text.ParseException pe) { JOptionPane.showMessageDialog(null, "Your parse got PWNT"); } // Get Date 2 try { Date d2 = df.parse("2001-03-02"); } catch(java.text.ParseException pe) { JOptionPane.showMessageDialog(null, "Your parse got PWNT"); } String relation; if (d1.equals(d2)) relation = "the same date as"; else if (d1.before(d2)) relation = "before"; else relation = "after"; System.out.println(d1 + " is " + relation + ' ' + d2); }
I am trying to comapre then display then in a text box using Try but it cannot read the varaibles because the operatin is outside the try is there anyway around this or a different way of doing this?

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-19-2007, 07:50 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // Get dates Date d1 = null; Date d2 = null; try { d1 = df.parse("2000-02-01"); d2 = df.parse("2001-03-02"); } catch(java.text.ParseException pe) { JptionPane.showMessageDialog(null, "parse error for: " + pe.getMessage()); } String relation; if (d1.equals(d2)) relation = "the same date as"; else if (d1.before(d2)) relation = "before"; else relation = "after"; System.out.println(df.format(d1) + " is " + relation + " " + df.format(d2)); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
String comparison abhiN New To Java 2 04-09-2008 06:47 AM
Comparison of Strings Cero.Uno New To Java 3 02-11-2008 04:46 AM
No fo days between two dates Java Tip Java Tips 0 01-28-2008 11:06 AM
Date comparison Rageagainst20 New To Java 0 12-19-2007 08:34 PM
String comparison sireesha New To Java 1 12-18-2007 02:16 AM


All times are GMT +3. The time now is 04:01 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org