• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

date format

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to convert the string which is in format (month day year )eg 16.05.99 to (year month day ) 19990516T120000.000Z format .For that i wrote folowing piece of code.Just it is taking lot of time about 300 milliseconds to convert each date.Is there some other way to achieve the same result faster.
public static String convertDate(String oldDate) throws Exception
{


SimpleDateFormat oldDateFormat = new SimpleDateFormat("dd.MM.yy'T'HHmmss.SSS'Z'");
oldDate = oldDate+"T120000.000Z" ;
java.util.Date dt = null;
dt = oldDateFormat.parse(oldDate);
SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS'Z'");

return newDateFormat.format(dt);
}
tahnks,
peter
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
300 ms seems an awfully long time, even for that code. My system executes it ten times in 380 ms. Perhaps there's some other process tying up your system? Or perhaps the delay is not really caused by the convertDate() method, but by something else? Or maybe you've just got a slow system.
In any event, yes it's certainly possible to make the method faster. First, look at the two SimpleDateFormat objects. They never change, right? Why spend time creating them each time you execute this method? Parsing those initialization strings is at least as much work as parsing an input date. Instead, since they're constants, use a static variable for them. Then, look again at the hours/minutes/seconds part. It's constant too, right? The original input string can't have hours/minutes/seconds in it anyway, or you get a format exception when you concatenate a second hours/minutes/seconds onto it. So why bother parsing it each time? Just add the "T120000.000Z" at the end - less work for everyone:
[ May 28, 2002: Message edited by: Jim Yingst ]
 
peter brews
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply.
on my system it is taking 250-350 milliseconds. I am thinking of using string manipulation t convert the date in desired format.But having difficulty with having easy of converting char to int.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could any one please tell me the way to find out how much time a particular java program takes to run.
Thanks :roll:
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if Java provides a method that does that. what you can do is take the current time at the beggining of your main and at the end of your main, and just do the subtraction. It's a crude way, but it should work.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic