在Scala中添加格式化分钟

时间:2016-01-11 09:43:00

标签: scala

如何使用以下格式在scala中添加分钟

import java.text.SimpleDateFormat
import java.util.Calendar

val cal = Calendar.getInstance().getTime()
//val cal = Calendar.getInstance()


// create the date/time formatters
val dayFormat = new SimpleDateFormat("dd")
val monthFormat = new SimpleDateFormat("MM")
val yearFormat = new SimpleDateFormat("yyyy")
val hourFormat = new SimpleDateFormat("HH")
val minuteFormat = new SimpleDateFormat("mm")
val secondFormat = new SimpleDateFormat("ss")

val year = yearFormat.format(cal);
val month = monthFormat.format(cal);
val day = dayFormat.format(cal);
val hour = hourFormat.format(cal);
val minute = minuteFormat.format(cal);
val second = secondFormat.format(cal);

val AxedaRecvdDt = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + "Z"

1 个答案:

答案 0 :(得分:1)

如下所示:

import java.text.SimpleDateFormat
import java.util.Calendar

val cal = Calendar.getInstance()
//Why declare formats separately, format and concatenate when you can do just that in a single format
cal.add(Calendar.MINUTE, 30); // add mins here
val formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
val AxedaRecvdDt = formatter.format(cal.getTime())