如何格式化日期?

编程入门 行业动态 更新时间:2024-10-08 06:24:55
本文介绍了如何格式化日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我一直在试图格式化这个日期,但它一直给我不可分析日期错误?我想获得一个时间戳像2011-06-24T19:55:37Z是6月24日,2011年这里是code我使用。同样在一个侧面说明是收缩(如第一,第二,第三)可能吗?

的SimpleDateFormat自卫队=新的SimpleDateFormat(MM D,YYYY,Locale.US); 日期DT = sdf.parse(2011-03-01T17:55:15Z); time.setText(时间:+ dt.toString());

解决方案

现在的问题是,提供给SimpleDateFormat的构造函数的格式不符合您的日期格式。

字符串 MM D,YYYY 讲述的SimpleDateFormat如何跨preT 2011-03-01T17:55:15Z 。

建立一个格式字符串在的文档描述。

Hello I have been trying to format this date but it keeps giving me in unparsable date error? I am trying to get a time stamp like 2011-06-24T19:55:37Z to be June 24, 2011. here is the code I am using. Also on a side note is contraction (like the 1st, 2nd, 3rd) possible?

SimpleDateFormat sdf = new SimpleDateFormat("MM d, yyyy", Locale.US); Date dt = sdf.parse("2011-03-01T17:55:15Z"); time.setText("Time: " + dt.toString());

解决方案

The problem is that the format provided to SimpleDateFormat's constructor doesn't match the format of your date.

The string MM d, yyyy tells SimpleDateFormat how to interpret 2011-03-01T17:55:15Z.

Building a format string is described in the docs.

更多推荐

如何格式化日期?

本文发布于:2023-05-28 00:46:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/308217.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!