I am converting date but it add one dot extra with month how to handle it

Viewed 924

I am obtaining the current time from the mobile device and changing the format using the following code:

  SimpleDateFormat currentdate = new SimpleDateFormat("MMM,dd,yyyy HH:mm:ss s");
               date_n = currentdate.format(calendar.getTime());

However on some mobile devices I am getting the following output

Mar.,11,2021 12:08:26 26

A dot appears after Mar. I don't want that dot. How to handle it? Any guidelines?

2 Answers

Try to specify a Locale (somewhere you want):

SimpleDateFormat currentdate = new SimpleDateFormat("MMM,dd,yyyy HH:mm:ss s", Locale.US);

Your problem is because how SimpleDateFormat displays a month depends on Locale. When you omit Locale, the default Locale of device's setting is used respectively. If the setting of a user's device sets a Locale which represents March as Mar., it does so. If you don't want that, you should specify a certain Locale explicitly.

SimpleDateFormat currentdate = new SimpleDateFormat("MMM,dd,yyyy HH:mm:ss s",Locale.ENGLISH);
Related