scala 字符串转date类型,以及date类型 day加减

it2022-05-05  128

package com.test.dmp.task.bidease import java.text.SimpleDateFormat import java.util.Date import java.util.Calendar import java.util.GregorianCalendar object Test { def main(args: Array[String]): Unit = { val time = "20190716" val sdf =new SimpleDateFormat("yyyyMMdd") //字符串 转date类型 val dayDate :Date = sdf.parse(time) val calendar = new GregorianCalendar; calendar.setTime(dayDate); //data时间减少1 calendar.add(Calendar.DAY_OF_MONTH,-1)//.add(calendar.DATE, 1); val current: Date = calendar.getTime(); val startTime = sdf.format(current) println("time::::"+startTime) } }

最新回复(0)