• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the date of today

 
Nico Yukiko
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write codes for getting today date
 
Sunil Kumar Gupta
Ranch Hand
Posts: 824
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Nico Yukiko
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i store the day,month,year into a variable so that i can store it into a database
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There appears to be many different ways of doing this.


I guess it all depends on what you are doing with your application.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic