Joda Time: Convert UTC to local

﹥>﹥吖頭↗ 提交于 2019-12-03 07:37:09

Here's what I use on a current project.

val marketCentreTime = timeInAnotherTimezone.withZone(DateTimeZone.forID("Australia/Melbourne"))

Does that help?

EDIT:

Here's something that takes a time in the current TZ and converts to Brisbane time. You can use the same principle.

Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.joda.time._                                            
import org.joda.time._

scala> def timestampBrisbane(date: DateTime): String = {                      
     |   date.withZone(DateTimeZone.forID("Australia/Brisbane")).toString 
     | }
timestampBrisbane: (date: org.joda.time.DateTime)String

scala> val date = new DateTime
date: org.joda.time.DateTime = 2010-10-28T16:22:03.481+11:00

scala> val dateBrisbane = timestampBrisbane(date)
dateBrisbane: String = 2010-10-28T15:22:03.481+10:00
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!