Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes Getting the date of today Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting the date of today" Watch "Getting the date of today" New topic

Getting the date of today

Nico Yukiko

Joined: Aug 24, 2005
Posts: 21
How to write codes for getting today date
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Hi Niko

Check this...............

Calendar cal = new GregorianCalendar();

// Get the components of the date
int era = cal.get(Calendar.ERA); // 0=BC, 1=AD
int year = cal.get(Calendar.YEAR); // 2002
int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ...
int day = cal.get(Calendar.DAY_OF_MONTH); // 1...
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday,2=Monday, ...

Hope this will solve ur problem

Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Nico Yukiko

Joined: Aug 24, 2005
Posts: 21
How can i store the day,month,year into a variable so that i can store it into a database
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
You can use the java.sql.Date class, which maps to the SQL DATE type:

Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
[ September 13, 2005: Message edited by: Ulf Dittmer ]
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
There appears to be many different ways of doing this.

I guess it all depends on what you are doing with your application.

Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
I agree. Here's the link:
subject: Getting the date of today
It's not a secret anymore!