Groovy date format for UTC with milliseconds

前端 未结 3 990
后悔当初
后悔当初 2021-01-07 17:35

I\'m having trouble finding a good way of formatting a UTC-time stamp with this format: yyyyMMdd-HH:mm:ss.

I wasn\'t able

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 17:59

    Use yyyyMMdd-HH:mm:ss.SSS

    This will get you milliseconds as well.

    Test Code:

    def now = new Date()
    println now.format("yyyyMMdd-HH:mm:ss.SSS", TimeZone.getTimeZone('UTC'))
    

提交回复
热议问题