Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting Date. How to format int values into date format?
    primarykey
    data
    text
    <p>I am able to format a <strong>CURRENT DATE</strong> date using the appropriate imported methods but formatting my own date (My birthday for instance) is another story. It works when a return it with the tostring method because I formatted it manually. Anyway, my question is: Can I format my birthday using the imports ?</p> <pre><code>import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Date2 { private int month; private int day; private int year; private Date today = Calendar.getInstance().getTime(); // create a short version date formatter private DateFormat shorFormatter = SimpleDateFormat .getDateInstance(SimpleDateFormat.SHORT); // create a long version of date format private DateFormat longFormattter = SimpleDateFormat .getDateInstance(SimpleDateFormat.LONG); // create date time formatter, medium for day, long for time private DateFormat mediuFormattter = SimpleDateFormat.getDateTimeInstance( SimpleDateFormat.MEDIUM, SimpleDateFormat.LONG); /************ Constructors ***************/ public Date2() { } public Date2(int dd, int mm, int yyyy) { this.day = dd; this.month = mm; this.year = yyyy; } /************ Getters setters ************/ public Date getToday() { return today; } public String getShorFormatter() { return shorFormatter.format(today); } public String getLongFormattter() { return longFormattter.format(today); } public String getMediuFormattter() { return mediuFormattter.format(today); } public int getMonth() { return month; } public void setMonth(int month) { this.month = month; } public int getDay() { return day; } public void setDay(int day) { this.day = day; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String tosString() { return month + "/" + day + "/" + year; } } public class DateFormatTest { public static void main(String[] args) { Date2 date2 = new Date2(23, 05, 1973); System.out.println(date2.getShorFormatter()); System.out.println(date2.getLongFormattter()); System.out.println(date2.getMediuFormattter()); System.out.println(date2.tosString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload