示例#1
0
 /*
  * <p>Returns the length of the duration in milli-seconds.</p>
  *
  * <p>If the seconds field carries more digits than milli-second order,
  * those will be simply discarded (or in other words, rounded to zero.)
  * For example, for any <code>Date</code> value <code>x</code>,</p>
  * <pre>
  * <code>new Duration("PT10.00099S").getTimeInMills(x) == 10000</code>.
  * <code>new Duration("-PT10.00099S").getTimeInMills(x) == -10000</code>.
  * </pre>
  *
  * <p/>
  * Note that this method uses the {@link #addTo(Date)} method,
  * which may work incorrectly with <code>Duration</code> objects with
  * very large values in its fields. See the {@link #addTo(Date)}
  * method for details.
  *
  * @param startInstant
  *      The length of a month/year varies. The <code>startInstant</code> is
  *      used to disambiguate this variance. Specifically, this method
  *      returns the difference between <code>startInstant</code> and
  *      <code>startInstant+duration</code>.
  *
  * @throws NullPointerException
  *      If the startInstant parameter is null.
  *
  * @return milliseconds between <code>startInstant</code> and
  *   <code>startInstant</code> plus this <code>Duration</code>
  *
  * @see #getTimeInMillis(Calendar)
  */
 public long getTimeInMillis(java.util.Date startInstant)
 {
     java.util.Calendar cal = new java.util.GregorianCalendar();
     cal.setTime(startInstant);
     this.addTo(cal);
     return(getCalendarTimeInMillis(cal) - startInstant.getTime());
 }
示例#2
0
        /*
         * Produces a string representation of the date in SQL format
         *
         * @return a string representation of the date in SQL format - {@code
         *         "yyyy-mm-dd"}.
         */
        public override String ToString()
        {
            java.util.Calendar c = new java.util.GregorianCalendar();
            c.setTimeInMillis(this.milliseconds);
            java.lang.StringBuilder sb = new java.lang.StringBuilder(10);

            format(c.get(java.util.Calendar.YEAR), 4, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.MONTH + 1), 2, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.DAY_OF_MONTH), 2, sb);

            return(sb.toString());
        }
示例#3
0
        /*
         * Adds this duration to a {@link Date} object.
         *
         * <p/>
         * The given date is first converted into
         * a {@link java.util.GregorianCalendar}, then the duration
         * is added exactly like the {@link #addTo(Calendar)} method.
         *
         * <p/>
         * The updated time instant is then converted back into a
         * {@link Date} object and used to update the given {@link Date} object.
         *
         * <p/>
         * This somewhat redundant computation is necessary to unambiguously
         * determine the duration of months and years.
         *
         * @param date
         *      A date object whose value will be modified.
         * @throws NullPointerException
         *      if the date parameter is null.
         */
        public void addTo(java.util.Date date)
        {
            // check data parameter
            if (date == null)
            {
                throw new java.lang.NullPointerException(
                          "Cannot call "
                          + this.getClass().getName()
                          + "#addTo(Date date) with date == null."
                          );
            }

            java.util.Calendar cal = new java.util.GregorianCalendar();
            cal.setTime(date);
            this.addTo(cal);
            date.setTime(getCalendarTimeInMillis(cal));
        }
示例#4
0
 /**
  * <p>Returns the length of the duration in milli-seconds.</p>
  *
  * <p>If the seconds field carries more digits than milli-second order,
  * those will be simply discarded (or in other words, rounded to zero.)
  * For example, for any <code>Date</code> value <code>x</code>,</p>
  * <pre>
  * <code>new Duration("PT10.00099S").getTimeInMills(x) == 10000</code>.
  * <code>new Duration("-PT10.00099S").getTimeInMills(x) == -10000</code>.
  * </pre>
  *
  * <p/>
  * Note that this method uses the {@link #addTo(Date)} method,
  * which may work incorrectly with <code>Duration</code> objects with
  * very large values in its fields. See the {@link #addTo(Date)}
  * method for details.
  *
  * @param startInstant
  *      The length of a month/year varies. The <code>startInstant</code> is
  *      used to disambiguate this variance. Specifically, this method
  *      returns the difference between <code>startInstant</code> and
  *      <code>startInstant+duration</code>.
  *
  * @throws NullPointerException
  *      If the startInstant parameter is null.
  *
  * @return milliseconds between <code>startInstant</code> and
  *   <code>startInstant</code> plus this <code>Duration</code>
  *
  * @see #getTimeInMillis(Calendar)
  */
 public long getTimeInMillis(java.util.Date startInstant)
 {
     java.util.Calendar cal = new java.util.GregorianCalendar();
     cal.setTime(startInstant);
     this.addTo(cal);
     return getCalendarTimeInMillis(cal) - startInstant.getTime();
 }
示例#5
0
        /**
         * Adds this duration to a {@link Date} object.
         *
         * <p/>
         * The given date is first converted into
         * a {@link java.util.GregorianCalendar}, then the duration
         * is added exactly like the {@link #addTo(Calendar)} method.
         *
         * <p/>
         * The updated time instant is then converted back into a
         * {@link Date} object and used to update the given {@link Date} object.
         *
         * <p/>
         * This somewhat redundant computation is necessary to unambiguously
         * determine the duration of months and years.
         *
         * @param date
         *      A date object whose value will be modified.
         * @throws NullPointerException
         *      if the date parameter is null.
         */
        public void addTo(java.util.Date date)
        {
            // check data parameter
            if (date == null)
            {
                throw new java.lang.NullPointerException(
                    "Cannot call "
                    + this.getClass().getName()
                    + "#addTo(Date date) with date == null."
                );
            }

            java.util.Calendar cal = new java.util.GregorianCalendar();
            cal.setTime(date);
            this.addTo(cal);
            date.setTime(getCalendarTimeInMillis(cal));
        }
示例#6
0
文件: Date.cs 项目: sailesh341/JavApi
        /**
         * Produces a string representation of the date in SQL format
         *
         * @return a string representation of the date in SQL format - {@code
         *         "yyyy-mm-dd"}.
         */
        public override String ToString()
        {
            java.util.Calendar c = new java.util.GregorianCalendar();
            c.setTimeInMillis(this.milliseconds);
            java.lang.StringBuilder sb = new java.lang.StringBuilder(10);

            format(c.get(java.util.Calendar.YEAR), 4, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.MONTH + 1), 2, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.DAY_OF_MONTH), 2, sb);

            return sb.toString();
        }
示例#7
0
 public virtual int getMinutes()
 {
     java.util.Calendar c = new java.util.GregorianCalendar();
     c.setTimeInMillis(this.milliseconds);
     return(c.get(java.util.Calendar.MINUTE));
 }
示例#8
0
 public virtual int getHours()
 {
     java.util.Calendar c = new java.util.GregorianCalendar();
     c.setTimeInMillis(this.milliseconds);
     return(c.get(java.util.Calendar.HOUR));
 }
示例#9
0
 public virtual int getYear()
 {
     java.util.Calendar c = new java.util.GregorianCalendar();
     c.setTimeInMillis(this.milliseconds);
     return(c.get(java.util.Calendar.YEAR) - 1900);
 }
示例#10
0
 public virtual int getDate()
 {
     java.util.Calendar c = new java.util.GregorianCalendar();
     c.setTimeInMillis(this.milliseconds);
     return(c.get(java.util.Calendar.DAY_OF_MONTH));
 }