public class Message {
 private static java.text.DateFormat FORMAT_DATE;
 private static java.text.DateFormat FORMAT_TIME;
 private Time published;
 public Message(java.text.DateFormat df, java.text.DateFormat tf) {
  FORMAT_DATE = df;
  FORMAT_TIME = tf;
  published = new Time();
 }
 public void setPublished(String published) {
  try {
   this.published.parse3339(published.trim());
  } catch (TimeFormatException e) {
   throw new RuntimeException(e);
  }
 }
 public String getPublished() {
  Date date = new Date(published.normalize(true));
  return FORMAT_DATE.format(date) + " " + FORMAT_TIME.format(date);
 }
RFC3339については、以下にドキュメントがある。
RFC3339 - Date and Time on the Internet: Timestamps
コンストラクタの引数のjava.text.DateFormatで、端末側で選択されているロケール・書式に則った、日付と時間の書式を渡している。これによって、ユーザが設定している書式に則って、日付と時間をフォーマットしている。
Message message = new Message(android.text.format.DateFormat.getDateFormat(context), android.text.format.DateFormat.getTimeFormat(context));
 
 
0 件のコメント :
コメントを投稿