SalesforceのApexで、DateTime
からTime
への変換は同様に簡単です。DateTime
オブジェクトからTime
オブジェクトに変換するには、time
メソッドを使用します。以下は例です。
apex
DateTime dateTimeValue = DateTime.now();
Time timeValue = dateTimeValue.time();
上記の例では、DateTime.now()
で現在の日時を取得し、それをtime()
メソッドを使用してTime
型に変換しています。
特定のDateTime
オブジェクトを変換したい場合は、そのオブジェクトを使用して同じようにtime()
メソッドを呼び出すことができます。
apex
DateTime specificDateTime = ...; // 任意のDateTimeオブジェクト
Time specificTime = specificDateTime.time();
これで、specificTime
にはspecificDateTime
の時間部分が含まれています。