如何从 Scala 中的日期时间到小时
How to get only till hour from datetime in scala
如何使用 joda time 在 scala 中获得以下输出
input: 2016-04-26T21:00:00+00:0
output:2016-04-26 21:00:00
谢谢,
这个好像可以-
$ scala -cp joda-time-2.9.jar
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> import org.joda.time.DateTime
import org.joda.time.DateTime
scala> import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormat
scala> val fmt2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ")
fmt2: org.joda.time.format.DateTimeFormatter = org.joda.time.format.DateTimeFormatter@12f40c25
scala> import org.joda.time.DateTimeZone
import org.joda.time.DateTimeZone
scala> val x = fmt2.parseDateTime("2016-04-26T21:00:00+00:00").withZone(DateTimeZone.UTC)
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
x: org.joda.time.DateTime = 2016-04-26T21:00:00.000Z
scala> x.withMinuteOfHour(0).withSecondOfMinute(0)
res0: org.joda.time.DateTime = 2016-04-26T21:00:00.000Z
scala> val fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
fmt: org.joda.time.format.DateTimeFormatter = org.joda.time.format.DateTimeFormatter@42dafa95
scala> fmt.print(res0)
res1: String = 2016-04-26 21:00:00
如何使用 joda time 在 scala 中获得以下输出
input: 2016-04-26T21:00:00+00:0
output:2016-04-26 21:00:00
谢谢,
这个好像可以-
$ scala -cp joda-time-2.9.jar
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> import org.joda.time.DateTime
import org.joda.time.DateTime
scala> import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormat
scala> val fmt2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ")
fmt2: org.joda.time.format.DateTimeFormatter = org.joda.time.format.DateTimeFormatter@12f40c25
scala> import org.joda.time.DateTimeZone
import org.joda.time.DateTimeZone
scala> val x = fmt2.parseDateTime("2016-04-26T21:00:00+00:00").withZone(DateTimeZone.UTC)
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
warning: Class org.joda.convert.FromString not found - continuing with a stub.
warning: Class org.joda.convert.ToString not found - continuing with a stub.
x: org.joda.time.DateTime = 2016-04-26T21:00:00.000Z
scala> x.withMinuteOfHour(0).withSecondOfMinute(0)
res0: org.joda.time.DateTime = 2016-04-26T21:00:00.000Z
scala> val fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")
fmt: org.joda.time.format.DateTimeFormatter = org.joda.time.format.DateTimeFormatter@42dafa95
scala> fmt.print(res0)
res1: String = 2016-04-26 21:00:00