File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to create a Data variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to create a Data variable" Watch "how to create a Data variable" New topic

how to create a Data variable

Edwin Davidson

Joined: Nov 26, 2003
Posts: 27
class daysold
public static void main(String x[])
//import and format the date to start with
// String birthdate=x[0];
String birthdate="1961-01-18";
int birthyear =Integer.valueOf( birthdate.substring(0,4)).intValue();
int birthmonth =Integer.valueOf( birthdate.substring(5,7)).intValue();
int birthday =Integer.valueOf( birthdate.substring(8)).intValue();
Above is my code. Now I have 3 int variables that I wish to combine into a Date variable such as:
Date mybirthday=new Date(int,int,int);
I know already that the Date line right above is dead wrong. I hear that Java really screwed up on the whole date/time class thing anyway. Now you need GregorianCalendar to create a Date object. So, how do I make a birthday Date variable that I can do date arithmetric with ? And is there a really good tutorial on date and time creatio/manipulation sonewhere ?
Thanks - Javaranch rocks !
Edwin Davidson
freezing my behind on in winter in Halifax, Nova Scotia in Canada !
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
Yeah, you have to use a GregorianCalendar. I *think* (this is kinda guesswork) that it's designed to replace java.util.Date (there's also java.sql.Date). It handles I18N much better and has the constructor you want. java.util.Date also has a constructor that takes parameters like you want, but it's been deprecated.
Anyway, this is the sort of thing you'll want to do:


I agree. Here's the link:
subject: how to create a Data variable
It's not a secret anymore!