• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic