3

私は android.text.format.Time を使用しています。文字列を取得してその文字列を Time オブジェクトに変換する関数が必要です。他の理由で、最初に時間オブジェクトを文字列として保存しました。文字列を Time オブジェクトに渡すだけです。コード:

 Time time = new Time();
 String time = time.toString();

  Time t = new Time();
  t.parse(time);
  this.time = t;

t.parse(time) 

ブール値を与えます。

boolean value = time.parse(s)

パラメータ: time - 解析する文字列 戻り値: true - 結果の時間値が UTC 時間の場合

4

1 に答える 1

4
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2012-12-14 14:05:59");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
Time time = new Time();
time.set(int second, int minute, int hourOfDay, int monthDay, int month, int year);

// int second => calendar.get(Calendar.SECOND);
// etc minute, hourOfDay, monthOfDay, month, year...
于 2012-12-14T09:02:40.537 に答える