美文网首页Android程序员Java
华为 mate7 SimpleDateFormat YYYY问题

华为 mate7 SimpleDateFormat YYYY问题

作者: 大校啊 | 来源:发表于2017-12-01 18:24 被阅读23次

今天遇到一个在华为mate7、小米5、三星上崩溃的问题
代码是

SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm", Locale.CHINA);

崩溃原因是“YYYY”导致的,最后看SimpleDateFormat 的源代码,发现

public class SimpleDateFormat extends DateFormat {

    private static final long serialVersionUID = 4774881970558875024L;

    // 'L' and 'c' are ICU-compatible extensions for stand-alone month and stand-alone weekday.
    static final String PATTERN_CHARS = "GyMdkHmsSEDFwWahKzZLc";

YYYY是无法解析的,在有的手机上会出现这个问题,建议用“yyyy”

相关文章

网友评论

    本文标题:华为 mate7 SimpleDateFormat YYYY问题

    本文链接:https://www.haomeiwen.com/subject/lziwbxtx.html