gpt4 book ai didi

android 中 java.text.parseeException 不可解析的日期

转载 作者:行者123 更新时间:2023-12-01 18:52:51 27 4
gpt4 key购买 nike

String dt=mDateButton.getText().toString();
String tm =mTimeButton.getText().toString();
try {
String format ="dd-MM-yyyy hh:mm a";

DateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);

String v_date_str = dt + " " + tm;
// String setDate =sdf.format(dt + " " + tm);
Date v_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH).parse(v_date_str );

DateFormat formatter = null;
formatter = new SimpleDateFormat("dd-MMM-yyyy");

Log.d("sset: ", ""+formatter.format(v_date));
} catch (ParseException e) {
e.printStackTrace();
}

注意:其中 dt = 2013-03-02 且 tm = 21:54 。但我在第 9 行遇到错误。我不知道是什么原因。请帮助我摆脱这个问题。预先感谢您。

最佳答案

问题是您的 DateFormat 模式不匹配。

由于 v_date_str2013-03-02 21:54,您可以使用以下方式匹配其格式:

new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ENGLISH)

关于android 中 java.text.parseeException 不可解析的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15194160/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com