File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transforming Dates with SimpleDateFormat

 
Robert Popular
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All:
I am getting the current date/time by performing
java.util.Date date = (Calendar.getInstance()).getTime()
It returns this format: Wed Oct 16 11:41:29 CDT 2002
I need to transform this into the following format:
yyyyMMddHHmmssZ
Using the SimpleDateFormat as follows, I get an Unparseable date error.
public String getLDAPDateFormat(java.util.Date date)
{
SimpleDateFormat sdfDateFormat = new SimpleDateFormat(BatchConstants.DATE_LDAP_PATTERN);
try
{
date = sdfDateFormat.parse(date.toString());
System.out.println("REMOVE): LastLogin=" +date.toString());
}
catch(java.text.ParseException pe)
{
pe.printStackTrace();
}
return date.toString();
}
Can you tell me where the gap in my thinking is? How can I get the first format into the second?
Thanks in advance!
bp
 
Robert Popular
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, So I found the hole in the thinking and replaced the code with the following:

However, I am getting the following error with the 'Z' in my pattern yyyyMMddHHmmssZ.

Any ideas?
Thanks!
 
James Swan
Ranch Hand
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you wanted the timezone info to appear on your formatted date then you should use lowercase 'z'
eg.
yyyyMMddHHmmssz
Or if you wanted the literal 'Z' to appear at the end of the formatted date the do this:
ldapDate = sdfDateFormat.format(date) + "Z";
 
Dave Landers
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Z is a new formatting character for JDK 1.4 to handle RFC 822 time zones. If you are looking at the 1.4 docs, make sure you are running with a 1.4 JDK.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic