Results 1 to 3 of 3
- 01-07-2012, 07:59 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 41
- Rep Power
- 0
stuck on writing Date application
I have to write an application to convert a date entered from the keyboard in the format 5/06/2000 to May 5, 2000 and then display the day of the year. I have to use arrays to store the names of the months as well as the days in each month. This is the code I have so far, but I don't know how proceed after the user inputs the date. How do I begin converting the input date from one format to another?
import java.util.Scanner;
import java.util.*;
public class ConvertDate
{
public static void main(String[] args)
{
String aDate;
String[] month = {"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};
int[] numberOfDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Scanner input = new Scanner(System.in);
System.out.println("Please enter a date using the MM/DD/YYYY format:");
aDate = input.nextLine();
//need to find how to convert the input to the Month name
//need to find a way to use the Gregorian Calendar to
//convert the input day and month to the day of the year
}
}
- 01-07-2012, 08:30 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: stuck on writing Date application
SimpleDateFormat (Java Platform SE 6)
GregorianCalendar (Java Platform SE 6)
If you can use other classes, you could use the SimpleDateFormatter with the pattern "MM/dd/yyyy" and the method parse to parse the aDate-string to an date object (otherwise: you could use the split method of the string class and Integer.parseInt)
//need to find a way to use the Gregorian Calendar to
create a gregoriancalendar object and setTime and pass the date object
//need to find how to convert the input to the Month name
month[gregoriancalendarobject.get(Calendar.MONTH)] , see API-doc
//convert the input day and month to the day of the year
gregoriancalendarobject.get(Calendar.DAY_OF_YEAR) , see API-doc
- 01-07-2012, 08:31 PM #3
Similar Threads
-
Inserting current date to oracle Date data type
By bartolay13 in forum JDBCReplies: 5Last Post: 02-16-2012, 09:26 AM -
Is their any method which converts a Julian date to an actual date.
By renu in forum New To JavaReplies: 2Last Post: 05-12-2011, 04:52 PM -
Sample music application stuck in the middle of running the programm..
By satyaram435 in forum AWT / SwingReplies: 3Last Post: 04-05-2010, 11:02 PM -
Date application - help please!
By javanewbie12 in forum New To JavaReplies: 6Last Post: 12-08-2009, 02:07 AM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks