943,634 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 683
  • Java RSS
Jun 10th, 2009
0

date format

Expand Post »
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.
Last edited by coolbuddy059; Jun 10th, 2009 at 6:42 pm.
Similar Threads
Reputation Points: 1
Solved Threads: 0
Light Poster
coolbuddy059 is offline Offline
45 posts
since Aug 2008
Jun 10th, 2009
0

Re: date format

SimpleDateFormat

(maybe)
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Jun 11th, 2009
0

Re: date format

SimpleDateFormat class is needed

Java Syntax (Toggle Plain Text)
  1. ......
  2. String yourdate="12-Aug-2009";
  3. String currformat="dd-MMM-yyyy";
  4. SimpleDateFormat fd=new SimpleDateFormat(currformat);
  5. Date d1=fd.parse(yourdate);
  6.  
  7. System.out.println(d1);
  8. String newformat="dd-MM-yyyy";
  9. fd.applyPattern(newformat);
  10. StringBuffer b=new StringBuffer();
  11. System.out.println(fd.format(d1,b,new FieldPosition(0)));
  12. ....
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 11th, 2009
0

Re: date format

Click to Expand / Collapse  Quote originally posted by adatapost ...
SimpleDateFormat class is needed

Java Syntax (Toggle Plain Text)
  1. ......
  2. String yourdate="12-Aug-2009";
  3. String currformat="dd-MMM-yyyy";
  4. SimpleDateFormat fd=new SimpleDateFormat(currformat);
  5. Date d1=fd.parse(yourdate);
  6.  
  7. System.out.println(d1);
  8. String newformat="dd-MM-yyyy";
  9. fd.applyPattern(newformat);
  10. StringBuffer b=new StringBuffer();
  11. System.out.println(fd.format(d1,b,new FieldPosition(0)));
  12. ....
You could have printed this:
Java Syntax (Toggle Plain Text)
  1. //fd.format(d1)
  2. System.out.println( fd.format(d1) );
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: J2ME Certification Tutorial
Next Thread in Java Forum Timeline: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC