Correct formatting for date

Asked

Viewed 54 times

0

I am formatting the start date of a list according to the code below, and in the database the dates registered in "2018-11-01" and "2018-11-02" are being listed respectively with the dates in "31/10/2018" and "01/11/2018" on the screen.

frontend code:

{{material.dataInicio | date: 'dd/MM/yyyy' }}

Note: The other dates are correct.

  • Try it this way: {{ material.dataInicio | date: 'dd/MM/yyy' | 'UTC' }}

  • @Sorack, I tried the procedure, but without success.

  • What is your version of Angularjs?

  • @Sorack, the version is 1.7.x

  • @Sorack, the thing is, some dates are showing different dates than the ones registered at the base. Examples: 2018-11-01 at the base and on the list 31/10/2018 or at the base 2018-11-02, on the list 01-11-2018. It’s like taking the last day, but other dates, they’re all normal.

  • When you give a console.log(material.dataInicio) what appears on the console?

  • My guess is that time zone configured in the bank is not the same as the frontend, hence the difference (guess based on nothing, because I do not know how the angular works with dates). If you please [Edit] the question putting the field types, both in the bank and in the frontend, in addition to the values and the error message you mentioned in the comment below, maybe gives us more clues than can be

  • @hkotsubo, I was able to resolve it through the backend. Using Simpledateformat sdf = new Simpledateformat("dd/MM/yyyy"); I created a private attribute Transient String dataInicioStr; Then I passed this Simpledateformat string => material.setDataInicioStr(sdf.format(material.getDataInicio()); and solved the problem.

Show 3 more comments

1 answer

0


Try to perform your formatting via Java.

As in the example below:

 SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy"); 
      dataFormatada.format(SuaData)

On the front you take this String that the format method will provide you

  • am implementing, but now is displaying a new String to Localdate conversion error.

  • Alysson, I decided on your solution. I created a private attribute Transient String dataInicioStr; then passed this material string.setDataInicioStr(sdf.format(material.getDataInicio()); and solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.