954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

date format

Can you help me with source code to get the date 1 jan 2009 in the format
01 01 09.

Actually I've to form a verification id for issuing gatepass which uses last two digit of the year,then net two digit consist of month and next three digit consist of number from 001 to 999 which increment by 1.

Please help me it's urgent.

coolbuddy059
Light Poster
45 posts since Aug 2008
Reputation Points: 1
Solved Threads: 0
 

SimpleDateFormat

(maybe)

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

SimpleDateFormat class is needed

......
       String yourdate="12-Aug-2009";
       String currformat="dd-MMM-yyyy";
       SimpleDateFormat fd=new SimpleDateFormat(currformat);
       Date d1=fd.parse(yourdate);

       System.out.println(d1);
       String newformat="dd-MM-yyyy";
       fd.applyPattern(newformat);
       StringBuffer b=new StringBuffer();
       System.out.println(fd.format(d1,b,new FieldPosition(0)));
       ....
__avd
Posting Genius (adatapost)
Moderator
8,647 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

SimpleDateFormat class is needed

......
       String yourdate="12-Aug-2009";
       String currformat="dd-MMM-yyyy";
       SimpleDateFormat fd=new SimpleDateFormat(currformat);
       Date d1=fd.parse(yourdate);

       System.out.println(d1);
       String newformat="dd-MM-yyyy";
       fd.applyPattern(newformat);
       StringBuffer b=new StringBuffer();
       System.out.println(fd.format(d1,b,new FieldPosition(0)));
       ....

You could have printed this:

//fd.format(d1)
System.out.println( fd.format(d1) );
javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You