Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date formatter

 
padma wundavalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the date formatter class to format the currentdate in the format "yyyymmdd". But in the output is in other format i.e "20013927" . Can anyone identify where I was doing wrong?
Any help is appreciated. Thanks in advance.
The code follows
/* use the pattern and currentlocale to custom format the date & time */
import java.util.*;
String DateTimeStr = "";
java.util.Date CurDate;
SimpleDateFormat formatter;
public GenerateSalesInvXML()
{
super();
formatter = new SimpleDateFormat("yyyymmdd");
CurDate = new java.util.Date();
DateTimeStr = formatter.format(CurDate);
}
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using the lower case m, which is for the minutes in the hour. Instead, use capital M, for month of the year. Something like:
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMdd");
Hope this helps
 
padma wundavalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Too much experience in the language like VB still has influence on overlooking the case sensitives.
Thanks again.
Padma
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic