• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to get the current date

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everybody:
I am workin in a small application . I want to get the current date in this format "mm\dd\yyyy"
can anyone tell me how to do that ?
rgds
siva
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi siva,
u can use

note that c.get(Calendar.MONTH) returns (current month -1) so i have added 1 to it.
regards
deekasha
regards
deekasha
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There Siva,
try using the abstract Class DateFormat on an instance of a Date Object, U can modify the formats of the Date.
check it out....
Bye,
Sheldon
 
Sheldon Rego
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way I tried out the syntax provided by the ranch hand had an error the actual value would be
String mmddyy = ""+(c.get(Calendar.MONTH)+1)+"/"+(c.get(Calendar.DATE))+"/"+(c.get(Calendar.YEAR));
See ya
Sheldon
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sheldon,
thanks for the correction.
regards
deekasha
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Deekasha:
What more should be done if I want the current date to be a Date type rather than a String type.
The reply is appreciated.
BQ

note that c.get(Calendar.MONTH) returns (current month -1) so i have added 1 to it.
regards
deekasha
regards
deekasha[/qb]<hr></blockquote>
[ November 12, 2002: Message edited by: Binqing Liu ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys try this,
public static java.sql.Date getCurrentDate()
{
//long currentTime=System.currentTimeMillis();
//return new java.sql.Date(currentTime);
Calendar mobjCalendar = Calendar.getInstance();
java.sql.Date mdtSQLDate = new java.sql.Date(mobjCalendar.getTime().getTime());
return mdtSQLDate;
}
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will lose the timestamp by using a java.sql.Date; Instead do this
java.util.Date currentDate = new Date();
Murali
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic