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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Month n Date - using Calendar
 
Similar Threads
help me on this.. :-)
get the current time
add(Calendar.DATE)
Time format problem in MIDLet
how to caculate first day / last day of a week ?