在Scala中转换日期格式 [英] Convert date format in Scala

查看:519
本文介绍了在Scala中转换日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将日期格式转换为以下格式:
2011-09-30 00:00:00.0
到scala中的20110930

有人有任何想法吗?

I am trying to convert a date format of that looks like this: 2011-09-30 00:00:00.0 to 20110930 in scala. Does anyone have any ideas?

推荐答案

使用类似这样的内容:

import java.text.SimpleDateFormat

val inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S")
val outputFormat = new SimpleDateFormat("ddMMyyyy")

val date = "2015-01-31 12:34:00.0"
val formattedDate = outputFormat.format(inputFormat.parse(date))

println(formattedDate) //20150131

这篇关于在Scala中转换日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆