ISO 8601中的Android时间 [英] Android time in iso 8601

查看:64
本文介绍了ISO 8601中的Android时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用android和joda time lib-我正在尝试转换用户的时区,以便稍后将其格式化为:2012-11-12T21:45:00 + 02:00.

using android and joda time lib - the I am trying to convert the user's timezone in order to format it later to : 2012-11-12T21:45:00+02:00 for example.

DateTimeZone zone = DateTimeZone.forID( TimeZone.getDefault().getID());

以上代码失败-谁知道我该如何获取欧洲/伦敦"(Timezone.getID)并将其转换为偏移量,以便将其设置为ISO 8601格式?

the above code fails - anyone know how can I take "Europe/London" (Timezone.getID) and convert it to an offset so I can put it in ISO 8601 format?

推荐答案

如果我正确理解了您的目标,则可以直接使用SimpleDateFormat类.

If I have correctly understood your objective you can use directly the SimpleDateFormat class.

示例代码:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.UK);
String formattedDate = sdf.format(new Date());

您可以在 SimpleDateFormat

致谢.

这篇关于ISO 8601中的Android时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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