Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

changing the date format in java method  RSS feed

 
Jacob James
Greenhorn
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!
Thanks
 
Tony Jackson
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.

Tony
 
Blake Minghelli
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!