• Post Reply Bookmark Topic Watch Topic
  • New Topic

difficulties in writing a function  RSS feed

 
Omar Ali
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am having a function that will accept the date as String in the format of "YYYY-MM-DD", But I want to format as "DD-MON-YYYY". So, I wrote this function but it did not work:



Can anyone help.... Thanks
 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Omar Ali: If this is an assignment, then avoid using Date.
You can accept the String in form of YYYY-DD-MM and in another string, transfer this as DD-MM-YYYY
simple to use forloop and '/' operator with some basic sense.
-Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"It did not work" does not provide any useful information.

Please read ItDoesntWorkIsUseless and provide more information.

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Small remark:

The convention is to use camel-case with method and variable names. So yours should be formatTheDate().
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the package statement of DateFormat
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The input and output formats are different - yyyy-MM-dd versus dd-MMM-yyyy (or is it dd-MMM-yy?). That means you need two DateFormat objects - one for parsing and one for formatting again.
 
Aniela Kącka
Greenhorn
Posts: 6
Hibernate Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Return statement is also missing, since your method is not of return type void.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Aniela!
 
Aniela Kącka
Greenhorn
Posts: 6
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice welcome, thank You Rob
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!