scala - how can I format DateTime using Anorm? -
i "time" mysql , need render fe, "time" in form of timestamp , want displayed yyyy-mm-dd hh:mm:ss, how can in server code follows?
object jditem { val jditem = { get[long]("id") ~ get[string]("name") ~ get[string]("url") ~ get[double]("price") ~ get[int]("commentnum") ~ get[int]("likerate") ~ get[datetime]("time") ~ get[string]("category") map { case id ~ name ~ url ~price~ commentnum~likerate~time~category => jditem(id,name,url,price, commentnum,likerate,time,category) } } implicit val jditemwrites: writes[jditem] = ( (jspath \ "id").write[long] , (jspath \ "name").write[string] , (jspath \ "url").write[string] , (jspath \ "price").write[double] , (jspath \ "commentnum").write[int] , (jspath \ "likerate").write[int] , (jspath \ "time").write[datetime] , (jspath \ "category").write[string] )(unlift(jditem.unapply)) def getjson(category:string,sort:string,descorasc:string):jsobject = db.withconnection{ implicit c => val list = sql("select id,name,url,price,commentnum,likerate,time,category "+category+" order "+sort+" "+descorasc+" limit 100").as(jditem *) val json:jsvalue = json.tojson(list) val jsobject = json.obj("total"-> list.length,"rows"-> json) jsobject }
}
since version 2.3.8 of anorm, joda & java8 temporal types supported in result parser; see anorm column: get[datetime]
.
Comments
Post a Comment