如何在安卓系统中将2021-07-06T19:27:46.811+0530格式转换为d MMM yyyy,hh:mm aaa格式 [英] How to convert 2021-07-06T19:27:46.811+0530 format to d MMM yyyy, hh:mm aaa this format in android

查看:0
本文介绍了如何在安卓系统中将2021-07-06T19:27:46.811+0530格式转换为d MMM yyyy,hh:mm aaa格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2021-07-06T19:27:46.811+0530->;当前值为字符串

我想将此格式转换为2021年5月7日06:45

提前谢谢

推荐答案

您可以这样做

JAVA:

SimpleDateFormat parserFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault());
SimpleDateFormat convertFormat = new SimpleDateFormat("dd/MM/yyyy, hh:mm a", Locale.getDefault());
Date date = null;
try {
    date = parserFormat.parse("2021-07-06T19:27:46.811+0530");
    if (date != null) {
        String formatedDate = convertFormat.format(date);
        Log.e("formatted date",formatedDate);
    }
} catch (ParseException e) {
    e.printStackTrace();
    Log.e("formatted date",e.getMessage());
}

科特林:

val parserFormat =
        SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault())
val convertFormat =
        SimpleDateFormat("dd/MM/yyyy, hh:mm a", Locale.getDefault())
var date: Date? = null
try {
     date = parserFormat.parse("2021-07-06T19:27:46.811+0530")
     if (date != null) {
        val formatedDate = convertFormat.format(date)
        Log.e("formatted date", formatedDate)
     }
} catch (e: ParseException) {
    e.printStackTrace()
    Log.e("formatted date", e.message!!)
}

这篇关于如何在安卓系统中将2021-07-06T19:27:46.811+0530格式转换为d MMM yyyy,hh:mm aaa格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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