aspose file tools*
The moose likes Beginning Java and the fly likes Date formatter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date formatter" Watch "Date formatter" New topic
Author

Date formatter

padma wundavalli
Greenhorn

Joined: Feb 22, 2001
Posts: 15
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

Joined: Sep 23, 2001
Posts: 158
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


Michael J Bruesch<br /><i>I code, therefore I am.</i>
padma wundavalli
Greenhorn

Joined: Feb 22, 2001
Posts: 15
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

Joined: Sep 23, 2001
Posts: 158
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date formatter