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



Home Answers Viewqa Date-Calendar java yesterday

Have Programming Question? Ask it here!
 
 
 


hendra
java yesterday
1 Answer(s)      5 years and 10 months ago
Posted in : Date-Calendar



Advertisement
View Answers

October 11, 2008 at 11:43 AM


for getting year month and days between two dates use following code

and for took a calender from another windwo use java script

package rajanikant.code.sep_2008;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateDifference {

public static void main(String s[]) throws ParseException{


Date date1 = new Date();
Calendar calendar = Calendar.getInstance();

calendar.setTime(date1);
int cur_month = calendar.get(Calendar.MONTH)+1;
int cur_year = calendar.get(Calendar.YEAR);
int cur_date = calendar.get(Calendar.DATE);
String df1 = cur_date + "-" + cur_month + "-" + cur_year;

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date2;
String newdate = "19-07-2006";
date2 = sdf.parse(newdate);
calendar.setTime(date2);
int month = calendar.get(Calendar.MONTH)+1;
int year = calendar.get(Calendar.YEAR);
int date = calendar.get(Calendar.DATE);

String df2 = date + "-" + month + "-"+ year;

int day = 0;
int no_of_days = 0;
int flag = 0;
if (cur_year % 4 == 0) {

if (cur_year % 100 != 0) {
flag = 1;
}
else if (cur_year % 400 == 0) {
flag = 1;
}
else {
flag = 0;
}
}
// It is not divisible by 4.
else {
flag = 0;
}
if(cur_month == 2){
if(flag == 1){
no_of_days = 29;
}else{
no_of_days = 28;
}
}


if(cur_month == 1 || cur_month == 3 || cur_month == 5 || cur_month == 7 || cur_month == 8 || cur_month == 10 || cur_month == 12){
no_of_days = 31;
}
if(cur_month == 4 || cur_month == 6 || cur_month == 9 || cur_month == 11){
no_of_days = 30;
}
if(cur_date > date){
day = cur_date - date;
}else{
day = cur_date - date + no_of_days;
cur_month = cur_month - 1;
}

if(cur_month > month){
cur_month = cur_month - month;
}else{
cur_month = cur_month - month + 12;
cur_year = cur_year - 1;
}
if(cur_year > year){
cur_year = cur_year - year;
}else{
cur_year = 0;
}

System.out.println("Difference Between " + df1 + " and " + df2 + " is : " +cur_year + " Year " + cur_month + " Month " +day + " Days");
}
}


Rajanikant


Related Tutorials/Questions & Answers:
java yesterday - Date Calendar
java yesterday  Afternoon,Yesterday i have a question that how to make date sustract, the result is to make 1 month and 1 day like this, right. now... a calender from another windwo use java script package rajanikant.code.sep_2008
java yesterday - Date Calendar
java yesterday  And how to make date format DD/MM/YYYY,thank's  Hi friend, Code to help solve the Problem : import java.util.Date; import java.text.SimpleDateFormat; public class SimpleFormatDate { public
Advertisements
Java get yesterday's date
Java get yesterday's date   ... the yesterday's date.  In the given example, we simply get the current date by using... dateFormat.format(cal.getTime()) will displayed the yesterday's date. cal.getTime
javascript yesterday date.
javascript yesterday date.  Hi, How can I display the yesterday's...() mydate.setDate(mydate.getDate()-1) document.write("Yesterday Date :" +mydate.getDate.... By above example you can easily get yesterday date.you can also put any
Java Inheritance Concept.
Java Inheritance Concept.  Yesterday i got confused with following question in an aptitude exam. Question:Class A,B,C have method named doit(). Class B extends Class A,Class C extends Class B.How will you call method doit
Java: String Exercise 1c
Java: String Exercise 1c Name ______________________ Assume the following: String a = "Adios"; String h = "Hasta luego"; Give the values...____________a.substring(1,2) 4____________"yesterday".substring(4).length() 5
java
java  Hi Mr.Deepak, As per the yesterday's question thanks for your reply but i dont have any problem with database url, the same url is connecting to database, i think the problem is i dont knw how to create bean file means
Java Stream Write Exception
Java Stream Write Exception  I am doing socket programming. I have two files called Server.java and client.java. Both programs were running successfully and successfully sending data to each other. Yesterday I added the following
Java Specialists - Java Tutorials
Java Specialists 2003-05-02 The Java Specialists' Newsletter [Issue 069b... such an obvious bit of information in an advanced Java newsletter. They were.... That comes to only 15.53% of Java Specialists knowing about this. Imagine how
Programming - Replace method
Java: Programming - Replace method Change all occurrences in a string.... The predefined Java function replace may not be used for this -- you have to write it yourself. Example CallReturnsComments replace("yesterday", "yes
java
java  diff bt core java and java
continue java - Date Calendar
continue java  How to make a subtract date from jframe like jtexfield, data can input into jtextfied ? and how to get year, yesterday a have a question about how to substract dd mm yyyy can in this subtract have a year.thank
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
java
java  sample code for RARP using java
java
java  RARP implementation using java socket
java
java   What is ?static? keyword
java
java  how can use sleep in java   which book learn of java language
java
java  different between java & core java print("code sample
java
java  different between java & core java print("code sample
java
java  how to edit text document by using java then how to edit starting and ending of text document by using java
java
java online telephone directory  i need coding for online telephone directory..by using java....pls help me
 

 

 

DMCA.com