SimpleDateFormat warning To get local formatting use getDateInstance(), getDateTimeInstance(), or getTimeInstance(),

后端 未结 3 1897
再見小時候
再見小時候 2020-12-25 10:30

Do i need to be worried about this warning? What if I ignore the warning?
What does this warning mean:
To get local formatting use getDateInstance(),

3条回答
  •  失恋的感觉
    2020-12-25 11:17

    Same for kotlin

            //example long 1372339860 
            fun getDateTime(unixSeconds: Long): String {
             val date = java.util.Date(unixSeconds * 1000L)
    
             val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.getDefault())
             return simpleDateFormat.format(date)
            }
    

    Call like this getDateTime(1372339860)

    It will return 27.6.2013 15:31:00 GMT +2 The GMT+2 because I'm in Germany and we have summer time. You can use Locale.US as well.

提交回复
热议问题