Motorola devices : org.threeten.bp.DateTimeException when parsing a date in ThreeTen

后端 未结 6 1791
猫巷女王i
猫巷女王i 2021-02-11 12:23

I have a very weird behaviour on some Motorola devices where LocalDateTime.now() is returning 0000-00-00T00:00:00.0 with ThreeTenABP.

The code

6条回答
  •  醉梦人生
    2021-02-11 12:42

    Try this:

    The SimpleDateFormat class works on java.util.Date instances.

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    
    String dateString = format.format( new Date()   );
    Date   date       = format.parse ( "2009-12-31" ); 
    

    Below is a list of the most common pattern letters you can use

    y   = year   (yy or yyyy)
    M   = month  (MM)
    d   = day in month (dd)
    h   = hour (0-12)  (hh)
    H   = hour (0-23)  (HH)
    m   = minute in hour (mm)
    s   = seconds (ss)
    S   = milliseconds (SSS)
    z   = time zone  text        (e.g. Pacific Standard Time...)
    Z   = time zone, time offset (e.g. -0800)
    

    Here are a few pattern examples

    yyyy-MM-dd           (2009-12-31)
    
    dd-MM-YYYY           (31-12-2009)
    
    yyyy-MM-dd HH:mm:ss  (2009-12-31 23:59:59)
    
    HH:mm:ss.SSS         (23:59.59.999)
    
    yyyy-MM-dd HH:mm:ss.SSS   (2009-12-31 23:59:59.999)
    
    yyyy-MM-dd HH:mm:ss.SSS Z   (2009-12-31 23:59:59.999 +0100)
    

    Might this will help you:)

提交回复
热议问题