• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Month n Date - using Calendar

 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want the month and date in a 2-digit format. So am using NumberFormat. But this doesn't compile...can u pls help me out...or r there any way(s) out???
import java.text.*;
import java.util.*;
public class dt{
public static void main(String kk[]){
NumberFormat nf = new DecimalFormat("00");
Calendar rightNow = Calendar.getInstance();
int month= rightNow.get(Calendar.MONTH)+1;
int day= nf.format(rightNow.get(Calendar.DAY_OF_MONTH));
System.out.println("Month is "+month);
System.out.println("Date is "+day);
}
}

Thanks in advance,

MSM
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mahesh Mamani:
Hello,
int month= rightNow.get(Calendar.MONTH)+1;
int day= nf.format(rightNow.get(Calendar.DAY_OF_MONTH));

Got the prob, actually the prob was with the return type of NumberFormat.format().
Changed the code...

MSM
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic