2017-09-21 6 views

答えて

2

作成は簡単です(長い「エポックからのミリ秒」を表し、与えられたと仮定した場合):

val b = new DateTime(a) 

をしかし、私は、著者は、所望の構文を取得する方法を知りたいと思ったと仮定し、これはとachivedすることができます以下のコード:

class LongExtension(private val l: Long) extends AnyVal { 
    def toDateTime = new DateTime(l) 
} 

implicit def toExtension(l: Long) = new LongExtension(l) 

今暗黙の変換がスコープで利用可能である場合、以下syntaxtを使用することができる。

val c = a.toDateTime 
+2

implicitsを扱う場合は、 '暗黙のdef dt(l:Long)= new DateTime(l);を実行します。 val c:DateTime = 12345l' – Dima

0
scala> import org.joda.time.DateTime 
import org.joda.time.DateTime 
scala> val b = new DateTime(a) 
b: org.joda.time.DateTime = 1970-01-15T12:25:26.278+05:30 
関連する問題