Convert SimpleDateFormat



  • Good afternoon, help me figure out the envelope of the calendar when I convert the calendar and the current time, he returns for more than a month and a year all right?

    введите сюда описание изображения

    This is the code used to convert the date, month and year:

    GregorianCalendar cse =  new GregorianCalendar();
    cse.setTimeInMillis(Long.parseLong(cursor.getString(cursor.getColumnIndex(KEY_PUBDATE)))); // дата новости
    cse.add(Calendar.DAY_OF_MONTH, 1);
    SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss Z", Locale.ENGLISH);
    String dateString = fmt.format(cse.getTime());
    Log.d("DMC6", "dateString  " + dateString );
    holder.textPubData.setText(dateString);
    


  • You have a line in your code:

    cse.add(Calendar.DAY_OF_MONTH, 1);
    

    If you see it, https://docs.oracle.com/javase/8/docs/api/java/util/GregorianCalendar.html#add-int-int- :

    Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

    So your code itself adds to the meaning of one day that prevents you.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2