SimpleDateFormat parsing date differently on some android devices

后端 未结 2 1089
旧时难觅i
旧时难觅i 2021-01-27 13:25

I am parsing the date as:

public class Consts{
public static final SimpleDateFormat DATE_FORMATTER_WITHOUT_TIME_ZONE = new SimpleDateFormat(
            \"yyyy-M         


        
2条回答
  •  灰色年华
    2021-01-27 14:28

    The difference is caused by different locales set up on devices.

    To mitigate the locale differences, you should use particular locale while formatting the date string. Here is a sample from my code, solving the same issue:

    new SimpleDateFormat(C.FORMAT_DATETIMEZ, Locale.US).format(new Date(time))
    

提交回复
热议问题