String, text, numbers, I/O II part
Visit us here and  you will find
much more tips!
Receive our  newsletter with new tips!  Almost 6,000 subscribers (by June 2001) can not be wrong! 
They read our tips every week! 
 To subscribe to The Java FAQ Daily send empty e mail to:
javafaq tips subscribe@topica.com
  or visit at:
http://www.topica.com/lists/javafaq tips/
 String, text, numbers, I/O II part
 Q: How do I parse it to date and make a date difference?? How many days in
between the String from and to?
I am always confusing with date and time.
I have 2 String, from and to
String from = "01.01.2001" //dd.MM.yyyy
String to = "01.03.2001" //dd.MM.yyyy
How do I parse it to date and make a date difference?? How many days in between
the String from and to?
Answer: 
import java.text.SimpleDateFormat;
import java.util.Date;
public class Tmp {
   public static void main( String argv[] ) throws Exception {
      long DAY = 24L * 60L * 60L * 1000L;
      SimpleDateFormat df = new SimpleDateFormat( "MM.dd.yyyy" );
      Date d1 = df.parse( "01.01.2001" );
      Date d2 = df.parse( "01.03.2001" );
      System.out.println( "The number days between:" );
      System.out.println( d1 );
      System.out.println( "and:" );
      System.out.println( d2 );
      System.out.println( "is: " + (( d2.getTime()   d1.getTime() ) / DAY )); 
   }
}
But the calculation of the difference in times may not be suitable due
to timezone issues and such. I believe there must be a better way?
Michael B. Allen
 Q: How do I convert a String to an integer. For example: String strSEQ =
file:///F|/a_jsite/350_tips/stings_text__date_numbers_io II.htm (1 of 7) [2001 07 08 11:25:00]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved