aspose file tools*
The moose likes Beginning Java and the fly likes Month n Date - using Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Month n Date - using Calendar" Watch "Month n Date - using Calendar" New topic
Author

Month n Date - using Calendar

Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
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

Joined: Jun 25, 2001
Posts: 110
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
 
Consider Paul's rocket mass heater.
 
subject: Month n Date - using Calendar