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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hendra
ask java
2 Answer(s)      6 years and 3 months ago
Posted in : Date-Calendar



Advertisement
View Answers

October 10, 2008 at 3:11 PM


Hi friend,


Code to help calculate the month and days :

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

public class DayDiff {

public static void main(String[] args) {

Date date = new Date();
SimpleDateFormat sdf;

//sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss aa");
sdf = new SimpleDateFormat("yyyy/MM/dd");
System.out.println("date " + sdf.format(date));

//string containing date in one format
String strDate1 = sdf.format(date);
String strDate2 = "2008/09/01";

try
{
//create SimpleDateFormat object with source string date format
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy/MM/dd");

//parse the string into Date object
Date date1 = sdfSource.parse(strDate1);
Date date2 = sdfSource.parse(strDate2);


long diff = date1.getTime() - date2.getTime();

long diffDays = diff / (24 * 60 * 60 * 1000);
long days =0;
long months=0;
if(diffDays%30!=0)
{
months = Math.round(diffDays/30);
days = diffDays%30;
System.out.println("months : " + months);
System.out.println("days : " + days);
}
if(diffDays%30==0)
{
months = diffDays/30;
System.out.println("months : " + months);

}


}
catch(ParseException pe)
{
System.out.println("Parse Exception : " + pe);
}
}
}

For more information on Java visit to :

http://www.roseindia.net

Thanks




October 10, 2008 at 3:43 PM


Check the Book "Exploring in C"

there this example present



Related Tutorials/Questions & Answers:
Ask about java
Ask about java  Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case
Ask java count
Ask java count  Good morning, I have a case where there are tables... | Java 1 | 10 | | b002 | beginner java | 5 | | b003 | advanced java book | 26 | | b004 | MySQL 1
Advertisements
ask java - Date Calendar
but in java i found too but i can't to join in another frame. And i want to ask how...ask java  sory i'am wrong language. i want to ask to this forum how... information on Java visit to : http://www.roseindia.net Thanks  
ask - Java Beginners
ask   dear how to "print out" into a file ? regard suhadi  Hi friend, Please explain properly requirement. I am sending simple...://www.roseindia.net/java/ Thanks. Amardeep
Ask Java Questions Online
Ask Java Questions Online       Now, it’s time to rejoice for the Java... Developer Company has just begun a new service ‘ask question online&rsquo
Ask make graph from i report and view to java Language Programming
Ask make graph from i report and view to java Language Programming  Dear sir, Please help me, i want to make a graph from mysql to i report and view to java. Please help me, give me example source code please. thank you
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
Ask about looping in database
Ask about looping in database  Good afternoon, I want to ask...=True,A2=True : code is the same data Rule and Heritage. I want to ask that how to read looping in field rights(if A1=false and A2 = True), use from java. i
Ask Questions with Options
Ask Questions with Options using Java In this section, we are going to ask five questions one after the other with four options to test the user. For this, we have stored 5 questions, answers with four options into a list. The list
Ask for latest version for hibernate
Ask for latest version for hibernate  any new version for hibernate after 3.0, if yes can u give some exmp for latest version of hibernate
Ask date difference
Ask date difference  Hello, I have a problem about how to calculate date, the result from this code is not complete , this is my code . please help me. thank you public void a(){ String date1 = jTextField33.getText(); String
Ask Questions
Ask Questions      ..., professions, students and learners, we have initiated a new service ‘Ask Question’. Using this new service, our visitors can ask any sort of question
ask a user to enter 5 integer
ask a user to enter 5 integer  make a program that enter 5 numbers then identify the largest and the smallest number sample program 2 4 3 5 6 the smallest number: 2 the largest number: is 6 66
Ask JSP questions online
Ask JSP questions online       Facing problem in JSP? Ask to us, we... has just started a new problem solving service ‘ask question’. In our
Ask Applet Questions Online
Ask Applet Questions Online   ... ‘Ask Questions’. Now, you can get the quick answers of your questions... service of ‘Ask Questions’ has given you the tool to resolve your
How to ask a questions to you clearly with normal english?
How to ask a questions to you clearly with normal english?  hi, i want to know how should or can i may ask a question. send me some format... in the same way as you have asked this question. Go to the Ask Questions part
Ask PHP Questions
Ask PHP Questions       PHP Questions and Answers Ask PHP Questions and get answers from.... In your questions and answers section you can ask PHP questions and get
Ask Servlet questions online
Ask Servlet questions online       Feel free to ask any question about servlets... kicked off a new service ‘ask questions’ to resolve your query
ask how function jCalender - Date Calendar
ask how function jCalender  d, Halo friend, i want to ask how to make this script can run and call JCalender. I want to know how to make private this code.i has already insert plugin in my netbeans. try
How many qusetions can you ask?
How many qusetions can you ask?  Hi I was very impressed following my very first question I asked regarding some coding. However I am not sure why any further questions have not yet been answered. Is this because they are more
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes  HI I have one problem I have fetched value from oracle database into grid... for more than One checkbox here is my code. <%@ page language="java" import
Ask JEE Questions Online
Ask JEE Questions Online       Java Platform, Enterprise Edition or Java... in the Java programming language. It is hardware and operating system
Ask Hibernate Questions Online
Ask Hibernate Questions Online   ... performance open source Java package that allows the developers to express queries.... Feel free to ask questions on Hibernate related problems. In the move
Ask iBatis Questions Online
Ask iBatis Questions Online   ... in Java, .NET, and Ruby on Rails. iBATIS is an additional layer of indirection... relating to programming, coding, implementing and using. Ask any iBatis
Ask Spring Questions Online
Ask Spring Questions Online   ... Framework for Java platform and .NET Framework. The prime feature of Spring... to their applications. Due to its flexibility, it has become very powerful among the Java
Ask JUnit Questions Online
Ask JUnit Questions Online       JUnit is a free, open source Java framework that makes... Java codes easier in its framework. It was originally written by Erich Gamma
Ask Struts Questions Online
Ask Struts Questions Online   ... framework for developing Java EE web applications. Struts uses and extends the Java Servlet API to encourage developers to adopt a model-view-controller (MVC
RMI Questions - Ask RMI question online
; Ask the Java RMI questions online and get answers. Programmers all over...RMI Questions - Ask RMI question online       Java RMI Questions RMI or Remote Method
Java coding for beginners
This article is for beginners who want to learn Java Tutorials of this section are especially for the beginners who want to incept the Java program from very beginning. Tutorial Java coding for beginners will enable you to know about
Ask Programming Questions and Discuss your Problems
Ask Programming Questions and Discuss your Problems  ... and your love for Java and Java and Java related fields, Roseindia Technologies... all sorts of Java related problems round the clock. Believe it. Roseindia has
Advertisements
 

 

 

DMCA.com