转换EEE mmm dd hh:mm:ss到dd-mm-yyyy hh:mm

时间:2014-09-19 13:46:30

标签: scala date

  def run : List[Map[String,Any]]={

    val startTime = "19-9-2014 23:00"
    val endTime = "19-9-2014 13:15"
    val df: SimpleDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm")
    val calendar: Calendar = Calendar.getInstance
    val finalTime : Date = df.parse(endTime)
    var firstTime=startTime
    var timeValuePair = List[Map[String , Any]]()
    var last = new Date()
    do {

      val first: Date = df.parse(firstTime)
      calendar.setTime(first)
      calendar.add(Calendar.MINUTE, 5)
      last = calendar.getTime
      val (repAlert, slowQueryAlert, statusAlert) = AggregateAlert.test(first.toString, last.toString)
      timeValuePair=Map("repAlert"->repAlert.toString,"slowQueryAlert"->slowQueryAlert.toString,"statusAlert"->statusAlert.toString) :: timeValuePair
      firstTime=last.toString
    }while(last.compareTo(finalTime)<0)

我基本上需要以dd-mmm-yyyy hh:mm的格式将日期和时间发送到startTime和endTime之间每5分钟间隔的函数AggregateAlert。 然而,我的代码我得到了#34;第一个&#34; as&#34; Fri Sep 19 11:00:00 IST 2014&#34;和&#34;最后&#34; as&#34; Fri Sep 19 19:01:21 IST 2014&#34;。但是我想要与dd-mmm-yyyy相同的格式。无论如何将它转换为所需的格式?

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试:

      val (repAlert, slowQueryAlert, statusAlert) = 
AggregateAlert.test(df.format(first), df.format(last))