0

I use Angular 15.0 and ASP.NET Core 5 and SQL Server for my project. I install Jalali-moment in my SPA project to record and get Shamsi dates. When I record the date in Jalali format (e.g. 1401-10-10) of course, the time also is attached to the date, it is converted to Gregorian date and stored in the database.

Now when I retrieve the same date from the database it shows the previous day (e.g. 1401-10-09), Of course not always? I uses Jalali pipe to show retrieved date as Shamsi format.

The Jalali pipe I used:

import * as moment from 'jalali-moment';
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
  name: 'jalali'
})
export class JalaliPipe implements PipeTransform {
  transform(value: any, args?: any): any {
    if (value === null || value === undefined) {
      return '';
    }
    const MomentDate = moment(value, 'YYYY/MM/DD');
    return MomentDate.locale('fa').format('YYYY/M/D');
  }
}

I know There is a time difference, but Jalali-moment package should have solved this difference problem. However I have this problem and how to solve it? best regards

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
R. Nourmandi
  • 157
  • 12
  • Does this answer your question? [Date becomes one (1) day behind after submitting model from Angular 6 to Web API](https://stackoverflow.com/questions/55985132/date-becomes-one-1-day-behind-after-submitting-model-from-angular-6-to-web-api) – Mohammad Aghazadeh Jan 01 '23 at 09:29
  • Thank you for your answer, I have a question about that answer you linked: Does the answer mean to manually convert the date to a string instead of using the toIsoString() conversion method? – R. Nourmandi Jan 01 '23 at 09:59
  • The answer looks like you need to convert the date manually. – Yiyi You Jan 04 '23 at 09:05

0 Answers0