• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

changing the date format in java method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone give me any tips how to change the date so that java can recognize it.

I mean

if a date such as 1/1/2004 is entered, then the method should return 01/01/2004. If you know what I mean?

Any help will be appreciated!
Thanks
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
J Js,

I'm not sure what you mean. You want a way to store dates? A way to enter dates? A way to create functions (methods) that act on dates? Are you looking for a method that can take a String entered (perhaps by a user on the keyboard) and convert it to a Date object?

Java has a Date class (java.util.Date) that is used to create Date objects. These objects represent specific points in time (ie, date and time). You can create a Date object using one of the class constructors and then you can use the Calendar class to work with the dates. The Calendar class and the GregorianCalendar classes are useful. In fact, the javadocs for GregorianCalendar has an informative code snippet which shows how you can work with dates. You should look at the javadocs for GregorianCalendar for more info.

Tony
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should also look at the javadocs for java.text.SimpleDateFormat - it can be used to parse strings that represent dates into actual java.util.Date objects, and format dates back into a string representation.
reply
    Bookmark Topic Watch Topic
  • New Topic