Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you should consider using <code>java.util.Calendar</code>. You provide a <code>java.util.Date</code>, then you can get all fields. A field would be <code>YEAR</code>, <code>DAY</code></p> <p><strong>EDIT (for comment)</strong></p> <p>I'll assume that in your code snippet <code>date1</code> is a string... it also seems that you know the format (mm/dd/yyyy or dd/mm/yyyy), so first you need a <code>SimpleDateFormat</code>:</p> <pre><code>final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); // or dd/MM/yyyy </code></pre> <p>Then you'll need a way to parse the date... parsing a date means to convert from a string to a date object:</p> <pre><code>final Date date = dateFormat.parse(date1); // date1 is a date in a string in the given format </code></pre> <p>You have a <code>Date</code>now... All you need is to extract information from it using a <code>java.util.Calendar</code></p> <pre><code>final Calendar calendar = new Calendar(); calendar.setTime(date); </code></pre> <p>With the <code>calendar</code>, you can get any date-related information. The first day of the month is trivial... any month starts with day number one... But for the last day of the month you need to get the maximum value for the <code>DAY_OF_MONTH</code> field:</p> <pre><code>int lastDayOfTheMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); </code></pre> <p>Anyway, I'm not making any of this stuff up... Feel free to browse the <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html" rel="nofollow">Calendar javadoc</a> and the <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html" rel="nofollow">SimpleDateFormat javadoc</a>. It's all there, and I'm sure it is better explained than by me.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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