Sample output :
[Minutes][Seconds.X]
[23][27.6]
[Minutes][Seconds.X]
[23][27.6]
//PS:93 scala> // c220 > a15 scala> import java.util.Calendar import java.util.Calendar scala> import java.text.SimpleDateFormat import java.text.SimpleDateFormat scala> val now = Calendar.getInstance().getTime() now: java.util.Date = Sat Apr 30 19:23:27 EDT 2016 scala> val myFormat = new SimpleDateFormat("mm.ss.SS") myFormat: java.text.SimpleDateFormat = java.text.SimpleDateFormat@15efcee0 scala> val minNmillisec = myFormat.format(now) minNmillisec: String = 23.27.636 // Use regex '.' scala> val splitted = minNmillisec.split("\\.") splitted: Array[String] = Array(23, 27, 636) scala> val min = splitted(0) min: String = 23 scala> val sec = splitted(1) sec: String = 27 scala> val millisec = splitted(2) millisec: String = 636 scala> val millisecTruncated = millisec(0) millisecTruncated: Char = 6 // Format string using String Interpolation (s/f/raw) scala> val result = f"[$min%2s][$sec%2s.$millisecTruncated%s]" result: String = [23][27.6]
No comments:
Post a Comment