SimpleDateFormat pattern based on locale, but forcing a 4-digit year

前端 未结 4 1606

I need to build a date format like dd/MM/yyyy. It\'s almost like DateFormat.SHORT, but contains 4 year digits.

I try to implement it with

4条回答
  •  -上瘾入骨i
    2021-02-15 17:34

    Can you not just use java.text.DateFormat class ?

    DateFormat uk = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK);
    DateFormat us = DateFormat.getDateInstance(DateFormat.LONG, Locale.US);
    
    Date now = new Date();
    String usFormat = us.format(now);
    String ukFormat = uk.format(now);
    

    That should do what you want to do.

提交回复
热议问题