aspose file tools*
The moose likes Java in General and the fly likes Date formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date formatting" Watch "Date formatting" New topic
Author

Date formatting

Asrita Saran
Greenhorn

Joined: Jul 11, 2007
Posts: 14
Hi..
I am facing some problem while formatting the date.


SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/DD");
java.util.Date d=sdf.parse(Edate.substring(0,9));
Date nd=new Date(sdf.format(d));


Im getting EDate value from a service in the format yyyy-mm-dd.
I have to set this date value to another method ,so im trying to convert the string to date.
When i try to print d and nd values ,it is not printimg the value i retrieved and it is printimg in the format dd/mm/yy.
What can i do to get the correct date and in the same format as yyyy/mm/dd?

Thanks in advance.
jeya prabha
Greenhorn

Joined: Jun 03, 2008
Posts: 23
you can use DateFormat class in java.text package
for example
DateFormat df = DateFormat.getDateInstance();
for (int i = 0; i < myDate.length; ++i) {
output.println(df.format(myDate[i]) + "; ");
}
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3168
    
  10
If the date you are reading uses '-' as a separator, why are you trying to reading it with a pattern that uses '/' as a separator ?


Joanne
jeya prabha
Greenhorn

Joined: Jun 03, 2008
Posts: 23
try this
import java.text.*;
import java.util.*;
class Dates3 {
public static void main(String[] args) {
Date d1 = new Date(1000000000000L);

DateFormat[] dfa = new DateFormat[6];
dfa[0] = DateFormat.getInstance();
dfa[1] = DateFormat.getDateInstance();
dfa[2] = DateFormat.getDateInstance(DateFormat.SHORT);
dfa[3] = DateFormat.getDateInstance(DateFormat.MEDIUM);
dfa[4] = DateFormat.getDateInstance(DateFormat.LONG);
dfa[5] = DateFormat.getDateInstance(DateFormat.FULL);

for(DateFormat df : dfa)
System.out.println(df.format(d1));
}
}
Asrita Saran
Greenhorn

Joined: Jul 11, 2007
Posts: 14
Sorry..i am using '-' as seperator in simpledateformat..Im getting one day less as result in the format dd/mm/yy
[ September 02, 2008: Message edited by: Asrita Saran ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date formatting
 
Similar Threads
Date Confusion
String date in to Date type
Parsing date..?
Formatting Date
Code review required for converting dateformat