UTC的Groovy日期格式,以毫秒为单位 [英] Groovy date format for UTC with milliseconds

查看:944
本文介绍了UTC的Groovy日期格式,以毫秒为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到格式化UTC格式的好方法: yyyyMMdd -HH:mm:ss。<另外三位数字>



我无法找到任何代表毫秒/百分之一的字符,我甚至不确定这是否可能,以解析该格式。



理想情况下,我想使用属于日期库的 parseToStringDate



我的计划b是将 yyyyMMdd-HH:mm:ss 转换为毫秒,然后将最后三位数字添加到该数字。

解决方案使用 yyyyMMdd -HH:mm:ss.SSS

$ b $
$ b

测试代码:



<$ p $
println now.format(yyyyMMdd -HH:mm:ss.SSS,TimeZone.getTimeZone('UTC'))
def now = new Date / code>


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

I wasn't able to find any character that represents milliseconds/hundredths, I'm not even sure this is possible, to parse that format that is.

Ideally I'd like to use the parseToStringDate that's part of the Date library.

My plan b is to convert yyyyMMdd-HH:mm:ss to milliseconds and then add the three last digits to that number.

解决方案

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'))

这篇关于UTC的Groovy日期格式,以毫秒为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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