java - 错误将此数据转换为日期(“HH:mm a”),(“dd MM”)和(“yyyy”)。如何将其划分为部分:D
问题描述
错误(java.text.ParseException:无法解析的日期:“2017 年 11 月 2 日 09:44:00:000AM”)
这是我在片段上使用的代码
String tanggal = dataObject.getString("tgl_periksa");
DateFormat readFormat = new SimpleDateFormat("MM dd yyyy HH:mm:ss:SSSa");
DateFormat writeFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = readFormat.parse( tanggal );
} catch ( ParseException e ) {
e.printStackTrace();
}
String formattedDate = "";
if( date != null ) {
formattedDate = writeFormat.format( date );
}
解决方案
将您的 readFormat 模式更改为它:
DateFormat readFormat = new SimpleDateFormat("MMM dd yyyy HH:mm:ss:SSSa")
推荐阅读
- python - Python中嵌套字典中的列表
- javascript - JavaScript 获取两个日期之间的天数
- python - 使用 xpath 从多个来源提取文本
- firebase - AgularFire 结合 2 个流
- php - 后期静态绑定中的对象静态属性
- emacs - Emacs 组织模式;在创建标题时插入 PROPERTIES 抽屉
- javascript - 如何获取角度可见元素的连续索引并忽略隐藏元素*ngFor的索引?
- php - 无法安装,频道“pecl.php.net”的 php_dir 不能被当前用户写入
- unity3d - 如何在统一着色图中将纹理与其他纹理混合,但仅在阴影侧?
- android - 我可以使用英语以外的语言作为默认资源吗?