scala/lift/date-time-converter.scala
changeset 6 b2c3a430fd59
equal deleted inserted replaced
5:824fbbce8e65 6:b2c3a430fd59
       
     1 package example
       
     2 
       
     3 object YmdDateTimeConverter extends DateTimeConverter {
       
     4   val df = new SimpleDateFormat("yyyy-MM-dd")
       
     5   val dtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
       
     6 
       
     7   def formatDateTime(d: Date) = dtf.format(d)
       
     8   def formatDate(d: Date) = df.format(d)
       
     9   /**  Uses Helpers.hourFormat which includes seconds but not time zone */
       
    10   def formatTime(d: Date) = hourFormat.format(d)
       
    11 
       
    12   def parseDateTime(s: String) = tryo { dtf.parse(s) }
       
    13   def parseDate(s: String) = tryo { df.parse(s) }
       
    14   /** Tries Helpers.hourFormat and Helpers.timeFormat */
       
    15   def parseTime(s: String) =
       
    16     tryo{hourFormat.parse(s)} or tryo{timeFormatter.parse(s)}
       
    17 }
       
    18 
       
    19 // vim: set ts=2 sw=2 et: