I'm totally new to Java . I want to print date format like this December 03, 2015.
Help me How to frame Java expression to print this Date format December 03, 2015
Thanks,
I'm totally new to Java . I want to print date format like this December 03, 2015.
Help me How to frame Java expression to print this Date format December 03, 2015
Thanks,
Use a SimpleDateFormat to generate custom date formats, for example...
System.out.println(new SimpleDateFormat("MMMM dd, yyyy", Locale.ENGLISH).format(new Date()));
which outputs
December 09, 2015
Try this
public class Test {
public static void main(String[] args) {
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("MMMMM dd, yyyy");
System.out.println(simpleDateFormat.format(new Date()));
}
}
for more info check this link: https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
public static void main(String[] args) {
printFormattedDate(new Date());
}
public static void printFormattedDate(Date date){
String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"Octorber", "November", "December"};
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
System.out.println(months[month] + " " + day + ", "+ year );
}
Hope it helps!
Have you tried using the object of Date class like this:
import java.util.Date;
public class DateDemo {
public static void main(String args[]) {
// Instantiate a Date object
Date date = new Date();
// display formatted date
System.out.printf("%s %tB %<te, %<tY",
"Due date:", date);
}
This would produce the following result:
Due date: February 09, 2004
In Java there is a really awesome print out function with formatting abilities. It is called Java Printf. There are many different ways to format the output so I highly suggest you research Java Printf, However, for your example, the Printf would be as follows:
System.out.printf("%s %02d, %d","December" ,3,2015);
Or a more abstract version that could be used in a method:
public void printDate(String month, int day, int year){
System.out.printf("%s %02d, %d",MonthName , Day , Year);
}