Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

changing the date format in java method

Posts: 9
  • Mark post as helpful
  • send pies
  • 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!
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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.

Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • 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.
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic