本文将分享Android棉花糖中的SimpleDateFormat行为更改的详细内容,并且还将对棉花糖app怎么不能用了进行详尽解释,此外,我们还将为大家带来关于androidSimpleDateFo
本文将分享Android棉花糖中的SimpleDateFormat行为更改的详细内容,并且还将对棉花糖app怎么不能用了进行详尽解释,此外,我们还将为大家带来关于android SimpleDateFormat(“dd / mm / yyyy”)效果不佳、Android SimpleDateFormat,如何使用?、Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退、android – SimpleDateFormat子类在这一年增加了1900的相关知识,希望对你有所帮助。
本文目录一览:- Android棉花糖中的SimpleDateFormat行为更改(棉花糖app怎么不能用了)
- android SimpleDateFormat(“dd / mm / yyyy”)效果不佳
- Android SimpleDateFormat,如何使用?
- Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退
- android – SimpleDateFormat子类在这一年增加了1900
Android棉花糖中的SimpleDateFormat行为更改(棉花糖app怎么不能用了)
我在Android
6.0(棉花糖)上遇到了日期格式问题。引发以下异常的代码是我的应用程序用于API请求(“客户端”)的纯Java库(单独构建)。如果相关的话,该库是用Java
1.6构建的……无论如何,这是代码。
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd E hh:mm aa", Locale.UK);Date eventDate = dateFormat.parse(StringUtils.substring(record, 0, 23).trim());
… record
具有价值;
2015-10-23 Fri 10:59 PM BST 3.60 meters
…“修剪”之后是;
2015-10-23 Fri 10:59 PMyyyy-MM-dd E hh:mm aa
该代码自Froyo成立以来一直有效,并且已经过单元测试。除了棉花糖,所有东西都会抛出异常。
10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: SynchroniseTidePosition.doInBackground10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: java.text.ParseException: Unparseable date: "2015-10-23 Fri 10:59 PM" (at offset 21)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.text.DateFormat.parse(DateFormat.java:579)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.oceanlife.rover.handler.XTideParser.parseResponse(XTideParser.java:69)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.brantapps.oceanlife.task.SynchroniseTidePosition.doInBackground(SynchroniseTidePosition.java:107)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at com.brantapps.oceanlife.task.SynchroniseTidePosition.doInBackground(SynchroniseTidePosition.java:43)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at android.os.AsyncTask$2.call(AsyncTask.java:295)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.FutureTask.run(FutureTask.java:237)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)10-23 21:01:56.816 4091-4110/com.oceanlife E/ParseException: at java.lang.Thread.run(Thread.java:818)
偏移量“ 21”是10:59中“ 9”之后的空格。谁能解释这个失败?
更新资料
切换到joda-time,它会显示更多信息的错误消息。这里是;
Invalid format ... is malformed at "PM"
…所以,这是关于要解析的字符串的AM / PM方面-
回到文档
答案1
小编典典在英国语言环境中,“ am”和“ pm”的定义似乎已更改。
在棉花糖中,英国区域设置现在将“ am”表示为“ am”,将“ pm”表示为“ pm”
String record = "2015-10-23 Fri 10:59 p.m. BST 3.60 meters"SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd E hh:mm aa", Locale.UK);// note the length is 25 now, not 23... Date eventDate = dateFormat.parse(StringUtils.substring(record, 0, 25).trim());
我无法解释为什么,但是美国语言环境与am / pm合作,英国与am / pm合作
编辑
似乎在2015年3月的en_gb
语言环境更新中,该语言环境已替换其am /
pm定义。源差异
android SimpleDateFormat(“dd / mm / yyyy”)效果不佳
private void setDateInTopBar() { Date bodyPartDate = DataManager.instance().getSelectedBodyPart().getPublicationDate(); SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy"); String formattedDate = format.format(bodyPartDate); TextView dateTxt = (TextView) findViewById(R.id.txtimageDate); dateTxt.setText(formattedDate); }
但我的月份是0,当日和年工作正常时,问题是什么?
解决方法
SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
附:
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
因为毫米参考分钟..检查http://developer.android.com/reference/java/text/SimpleDateFormat.html
Android SimpleDateFormat,如何使用?
我试图SimpleDateFormat
像这样使用Android :
String _Date = "2010-09-29 08:45:22"
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = fmt.parse(_Date);
return fmt.format(date);
}
catch(ParseException pe) {
return "Date";
}
结果很好,我有:2010-09-29
但是如果我更改SimpleDateFormat
为
SimpleDateFormat("dd-MM-yyyy");
问题是我会得到03-03-0035 !!!!
为什么以及如何获取格式dd-MM-yyyy
?
Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String dateStr = sdf.format(date);
应用闪退,有如下错误
java.lang.NoClassDefFoundError: android.icu.text.SimpleDateFormat
应用运行闪退是因为 这个方法在Android studio 中最低SDK版本24,
因为导入的包
import android.icu.text.SimpleDateFormat;
这个包在SDK 24版本之后才出现的
把这个包替换成Java原有的
import java.text.SimpleDateFormat;
即可解决
android – SimpleDateFormat子类在这一年增加了1900
public class ISO8601TLDateFormat extends SimpleDateFormat { private static String mISO8601T = "yyyy-MM-dd''T''HH:mm:ss.SSSZ"; public ISO8601TLDateFormat() { super(mISO8601T); } public ISO8601TLDateFormat(Locale inLocale) { super(mISO8601T,inLocale); } }
正如您所看到的,目的是生成或解释日期
2012-03-17T00:00:00.000 0100
这是Azure服务所期望的.但是,当我输入从DatePicker构造的Date对象时:
mDate = new Date(mDatePicker.getYear(),mDatePicker.getMonth(),mDatePicker.getDayOfMonth());
ISO8601TLDateFormat的输出是
3912-03-17T00:00:00.000 0100
正如你所看到的,这一年比我更多,或者不是未来的任何人都需要.我已经仔细检查了Date对象到Azure Feed系统的整个过程,它报告的日期是2012年,这是我所期望的.为什么SimpleDateFormat会破坏?
解决方法
public Date(int year,int month,int date) Deprecated. As of JDK version 1.1,replaced by Calendar.set(year + 1900,month,date) or GregorianCalendar(year + 1900,date). Allocates a Date object and initializes it so that it represents midnight,local time,at the beginning of the day specified by the year,and date arguments. Parameters: year - the year minus 1900. month - the month between 0-11. date - the day of the month between 1-31.
你需要记住,你构造的日期是0,1,是1900年1月1日.
关于Android棉花糖中的SimpleDateFormat行为更改和棉花糖app怎么不能用了的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android SimpleDateFormat(“dd / mm / yyyy”)效果不佳、Android SimpleDateFormat,如何使用?、Android studio 使用SimpleDateFormat格式化时间格式,导致程序闪退、android – SimpleDateFormat子类在这一年增加了1900的相关知识,请在本站寻找。
本文标签: