def getSeason(dateTime: DateTime): Int = {
(dateTime.getMonthOfYear - 1) / 3 + 1
}
import org.joda.time.DateTime
val dayS2="2019-03-02"
val des_file_day=DateTime.parse(dayS2).toString("yyyy-MM-dd-'Q%d'-'W'yyyyww").format(getSeason(DateTime.parse(dayS2)))
//2019-03-02-Q1-W201909 对的,默认解析的是yyyy-MM-dd
val dayS3="20190302"
val des_file_day3=DateTime.parse(dayS3).toString("yyyy-MM-dd-'Q%d'-'W'yyyyww").format(getSeason(DateTime.parse(dayS3)))
//20190302-01-01-Q1-W2019030201 错误
import org.joda.time.format.DateTimeFormat
val des_file_day4=DateTime.parse(dayS3,DateTimeFormat.forPattern("yyyyMMdd")).toString("yyyy-MM-dd-'Q%d'-'W'yyyyww").format(getSeason(DateTime.parse(dayS3,DateTimeFormat.forPattern("yyyyMMdd"))))
//2019-03-02-Q1-W201909 对的
scala日期操作
猜你喜欢
转载自blog.csdn.net/lsx6766/article/details/88722019
今日推荐
周排行