あなたがすでにDate
-objectを持っていること奇妙である、を経由してその標準出力を使用して、それをフォーマットしたいですtoString()
を開き、再びDate
オブジェクトに解析します。この手順では、元のDate
-objectのミリ秒の部分も失われます(myObj.getDate()
)。とにかく、解析を行うための適切なフォーマットのパターンは次のとおりです。
EEE MMMはHHをddは:MM:SSのZZZのYYYY
と英語のおSimpleDateFormat
-objectのロケールを設定することを忘れないでください。あなたはyyyy-partを2回持ち、 "H"(時)の代わりに "h"(am/pmの時)を使用したことに注意してください。 java.util.Date
のソースコードも参照してください。
/**
* Converts this <code>Date</code> object to a <code>String</code>
* of the form:
* <blockquote><pre>
* dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
* where:<ul>
* <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,
* Thu, Fri, Sat</tt>).
* <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,
* Jul, Aug, Sep, Oct, Nov, Dec</tt>).
* <li><tt>dd</tt> is the day of the month (<tt>01</tt> through
* <tt>31</tt>), as two decimal digits.
* <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through
* <tt>23</tt>), as two decimal digits.
* <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through
* <tt>59</tt>), as two decimal digits.
* <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through
* <tt>61</tt>, as two decimal digits.
* <li><tt>zzz</tt> is the time zone (and may reflect daylight saving
* time). Standard time zone abbreviations include those
* recognized by the method <tt>parse</tt>. If time zone
* information is not available, then <tt>zzz</tt> is empty -
* that is, it consists of no characters at all.
* <li><tt>yyyy</tt> is the year, as four decimal digits.
* </ul>
*
* @return a string representation of this date.
* @see java.util.Date#toLocaleString()
* @see java.util.Date#toGMTString()
*/
public String toString() {
// "EEE MMM dd HH:mm:ss zzz yyyy";
日付をフォーマットしようとすると、 'unparseable date'例外が発生しません。 [最小で完全で検証可能な例](http://www.stackoverflow.com/help/mcve)を提供してください。 –
@AndyTurner plsは私の編集をチェックします – Abx