Forums Register Login

Month n Date - using Calendar

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 979 times.
Similar Threads
how to caculate first day / last day of a week ?
help me on this.. :-)
Time format problem in MIDLet
get the current time
add(Calendar.DATE)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:24:28.