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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -