I have an MVC controller that is called via Ajax. That controller makes a query to a database returning a date (with 00:00:00 as the time value)
In a case, record stored in the SQL Server database has the value of "2019-05-01 00:00:00.000".
I am running this entity framework instructions:
var periodos = db.Periodo.Where(p => p.PeriodoEliminadoEn == null && p.ClienteId == this.ClienteID);
var listado = periodos.Select(p => new
{
PeriodoId = p.PeriodoId,
PeriodoFecha = p.PeriodoFecha,
PeriodoCreadoEn = p.PeriodoCreadoEn,
PeriodoActualizadoEn = p.PeriodoActualizadoEn,
PeriodoActivo = p.PeriodoActivo
});
GridRowObject grid = new GridRowObject(totalPages, currentPage, totalRecords, listado.ToList());
return Json(grid, JsonRequestBehavior.AllowGet);
GridRowObject is just this:
public class GridRowObject
{
public int total { get; private set; }
public int page { get; private set; }
public int records { get; private set; }
public IEnumerable rows { get; private set; }
public object userdata { get; set; }
public GridRowObject(int total, int page, int records, IEnumerable rows)
{
this.total = total;
this.page = page;
this.records = records;
this.rows = rows;
}
public GridRowObject(int total, int page, int records, IEnumerable rows, object userdata)
: this(total, page, records, rows)
{
this.userdata = userdata;
}
}
When the Ajax is made, the value of "PeriodoFecha" is ""/Date(1556679600000)/"" as I have seen in Chrome develoment tools.
I used this page, https://www.epochconverter.com/, to see real date value and I saw that it is: 1 May 2019 3:00:00 GMT and 30 de abril de 2019 23:00:00 local time.
The fact the page I developed shows the local date, which obviously is incorrect.
The problem is because of time zone problems in my country. According to government, timezone was changed before the change in other years. The server is not aware of that change. So, for the server, timezone is still GMT-3, however, real time zone is GMT-4. For that reason, all visitors' PC's show the date as April the 30th, which is obviously incorrect.
How can I get rid of time zone? I expect that, if the server serializes the date and time using its Json serializer, the date and time should be sent as is, without converting to GMT first.
And the client computer, when using "moment" jquery plugin to convert that json date back to date and time, be converted without considering time zone.
Regards
Jaime