Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


saurabh singh
date
1 Answer(s)      a year and 6 months ago
Posted in : Date-Calendar


can u tell me how to calculate difference between a user provided date and the system date in java


Advertisement
View Answers

June 1, 2013 at 5:27 PM


hi friend,

Try the following code may, this will be helpful for you

package net.roseindia;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class DateDifference {

    public static void main(String args[])
    {
        Date d = new Date();        
        Calendar cal1=Calendar.getInstance();
          cal1.setTime(d);
       Scanner scan = new Scanner(System.in); 
       System.out.print("Enter Date : ");
       String inputDate = scan.next();
       try {
        Date d1 = new SimpleDateFormat("dd-MM-yyyy").parse(inputDate);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(d1);       
        Date date1 = cal1.getTime();
        Date date2 = cal2.getTime();

        int days=(int)( (date1.getTime()-date2.getTime()) / (1000 * 60 * 60 * 24));
        System.out.println("Difference Between Date Is Of : "+ days +" No. Of Days");

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
    }   
}

Thanks.



Related Tutorials/Questions & Answers:
date
date   how to insert date in database? i need coding
date
date  i want difference between the date entered in a jtextfield and the system date in java
Advertisements
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
database table name birthday (DOB date); dob with DATE data type in database while...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try { System.out.println(date); Class.forName("oracle.jdbc.OracleDriver"); con
DATE
DATE  I have the following as my known parameter Effective Date... of calcultion starts My question is how to find the date of Thursday This cycle... the date of all the thursdays of the given year. import java.util.*; import
date format - Date Calendar
date format  how to convert dd-mmm-yyyy date format to gregorian... to convert date to calender. import java.util.*; import java.text.*; public...="19-Sep-2008"; DateFormat format ; Date date ; format = new
Date format - Date Calendar
Date format  please convert dd-mmm-yy date format to gregorian calendar date format.  Hi friend, Code related your Problem: import...]); Calendar calendar = new GregorianCalendar(pdt); Date time = new Date
Date Formay - Date Calendar
Date Formay  Sir, How to comapare two different date format in java.  Hi friend, Code to compare two different date import...)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format
date - Date Calendar
date   hi, sir i am doing student details project in swing but i am not getting current date in jtextfield in date it is giving ambigious error... label=new JLabel("Current Date: "); JTextField text=new JTextField(15
Date format - Date Calendar
Date format  Hi All, I am getting a date from database as a format 2010-15-07.I need to change it to 07/15/2010 and display it on my date field.Every time i need to check the format of the date field and make sure the correct
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
Date limit on Dojo Date picker - Date Calendar
Date limit on Dojo Date picker  Hi all, I am using dojo for date picker in my project. When user click on date text box, date picker will pop up. Using that component user can select date. Now I trying something different. I
date convertion
date convertion  How to convert the string date format 23/11/2009 to original date format in asp.net
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current  date. Understand with Example The Tutorial illustrate an example from 'DateTime
Date Picker
Date Picker  "I want to set default calendar date when using datepicker. This date means auto-loaded date when the calendar appears. The default date is the current date. I want to change it. How could I do
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
Date & Time
Date & Time  How to insert System Date & Time in MS-ACCESS using Java
date function
date function  Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following 1. Display the day no from the date 2. Display the year from the date 3. Display
PHP Date
PHP Date  Hi, How to use PHP Date functions in my PHP program? Thanks   Hi, PHP Date functions is very handy. It is used to progracess, format and create date objects in PHP. There are many ways to use PHP Date
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
Finding A Date
Finding A Date  My Frequency Start Date is 24-08-2012 My frequency end date - not defined Calculation Frequency is Weekly(Sunday) My calculation... the following date of sunday
date validation
date validation  sir, pls provide date validation code in javascript..we want to include it into our master form..   Please visit the following link: http://www.roseindia.net/mysql/datevalidation.shtml
Date prorblem
Date prorblem  HI all, i have date comming from one text file into string filed in java code. once the date is available in filed ( of type String... to insert the date into oracle DB. my code is as below: String DATEADDED
date program
date program  I have to differentiate my activities as todays... todays task if(dt==1){ //something to restrict date for today only using the 2variables else if(dt==10) //10days before task { //something to restrict date
Advertisements
 

 

 

DMCA.com