Java examples for Date Time:SimpleDateFormat
format day using SimpleDateFormat
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) { Date date = new Date(); /*from www .j av a 2 s .c o m*/ //formatting day in d format like 1,2 etc String strDateFormat = "d"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current day in d format : " + sdf.format(date)); //formatting day in dd format like 01, 02 etc. strDateFormat = "dd"; sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current day in dd format : " + sdf.format(date)); } }