0

I'm using Moment.js to convert my date , but it displayed a wrong year

below a part of my code in localized-moment.ts file :

transform(value: any, pattern: string = 'short'): any {

if (value.toString().includes('-')) {

  return moment(value).locale(this.translateService.currentLang).format('L LTS');

} else {

  if (!Number.isInteger(value)) {

    value = moment.unix(value);

  }
  
  return moment(value).locale(this.translateService.currentLang).format('L LTS');

}

}

then in my html , i'm using the pipe to convert :

        <td class="data-row">{{myTime | localizedMoment }}</td>

For example if value=1672828478537 after the call of pipe , I m getting 06/01/2023 12:12:36 instead of 06/01/2022 12:12:36

Thanks for your help in advance .

Ael9643
  • 3
  • 2
  • new Date(1672828478537) => Wed Jan 04 2023 12:34:38 GMT+0200 (for me). Are you sure it should be 2022? You can check additionally here: [www.epochconverter.com](https://www.epochconverter.com/). It does accept values in milliseconds and seconds. – Sergey Sosunov Jan 12 '23 at 14:15
  • @SergeySosunov yes it's supposed to be 2022, is that mean that the value i get from my WebService is wrong !! ? – Ael9643 Jan 12 '23 at 14:23
  • Im affraid - yes. `new Date("Wed Jan 04 2022 12:34:38 GMT+0200").getTime()` => `1641292478000`. – Sergey Sosunov Jan 12 '23 at 14:26

0 Answers0