• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Date format

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't use Java for full fledged programming, but I use it to do math calculations and date calculations for an Interactive Voice Response system. Here is my problem. The date format I get back from the following code is formatted as such 3/3/08. The problem is I need to get this format to read 03/03/08. Can someone tell me how? Below is the code.

calEndDate = Java.util.GregorianCalendar(intYear, intMonth, intDay)

{
//ADD 3 MONTHS TO START DATE
calEndDate.add(calEndDate.MONTH, 2);
//SUBTRACT 1 DAY FROM END DATE
calEndDate.add(calEndDate.DATE, (-1));
//SET DATE TO GREGORIAN CALENDAR RESULT
java.util.Date dateEndDate = calEndDate.getTime();
// RETURN TO SCRIPT
return dateEndDate;
}
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check java.text.SimpleDateFormat.
 
Johnny Sheppard
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that I tried that. Can you tell me what the syntax would be for my example?
Thanks,
 
Rob Spoor
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DateFormat format = new SimpleDateFormat("dd/MM/yy");

Mind the capital MM - if you use lowercase, it will take the minutes.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DateFormat df = new SimpleDateFormat("dd/MM/yy");
Date date= new Date();
String dateStr= df.format(orig);
 
grapes are vegan food pellets. Eat this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic