2014-09-19 45 views
-1
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的格式:毫米到功能AggregateAlert每startTime和endTime之間有5分鐘的時間間隔。 但是,通過我的代碼,我獲得了「第一次」作爲「2014年9月19日11:00:00 IST」和「最後」作爲「2014年9月19日19:01:21 IST」。不過我想要的格式與dd-mmm-yyyy相同。無論如何將其轉換爲所需格式?轉換EEE MMM DDD HH:MM:SS至DD-MM-YYY HH:MM

在此先感謝!

+0

你不隨地格式化你的日期。調用toString()只會讓你成爲默認的格式。 – soulcheck 2014-09-19 13:50:38

+0

val df:SimpleDateFormat = new SimpleDateFormat(「dd-MM-yyyy HH:mm」)這應該是正確的嗎? – Tanvi 2014-09-19 13:51:07

+0

是的,然後'df.format(第一)' – soulcheck 2014-09-19 13:51:47

回答

0

嘗試:

 val (repAlert, slowQueryAlert, statusAlert) = 
AggregateAlert.test(df.format(first), df.format(last)) 
相關問題