Format date without year

前端 未结 10 1526

How can create text representation of some date, that takes locale into account and contains only day and month (no year)?

Following code gives me s

10条回答
  •  既然无缘
    2020-12-25 13:01

    I did it this way:

    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    if (dateFormat instanceof SimpleDateFormat) {
        SimpleDateFormat simpleDateFormat = (SimpleDateFormat) dateFormat;
        String pattern = simpleDateFormat.toPattern();
    
        // I modified the pattern here so that dd.MM.yyyy would result to dd.MM
    
        simpleDateFormat.applyPattern(modifiedPattern);
    
        ... etc
    }
    

提交回复
热议问题