As a newcomer to web development, I recently came across an issue while testing some basic functionalities. In my database, I have data stored in SQL datetime format in UTC GTC timezone:
To display this data in a Kendo Grid and append "UTC" at the end of each date, I utilized the following code:
The problem arose when I attempted to convert the UTC datetime to local datetime using JavaScript's built-in Date type:
Interestingly, the first row of the grid was converted to a different timezone compared to the remaining rows.
Below is the code snippet I used to fetch and format the table:
$scope.mainGridOptions = {
pageable: true,
editable: true,
sortable: true,
dataSource: {
pageSize: 5,
transport: {
read: function (e) {
$http.get('/GetScheduler')
.then(function success(response) {
e.success(response.data)
}, function error(response) {
alert('something went wrong')
console.log(response);
})
}
},
schema: {
model: {
fields: {
"id": {
editable: false
}
}
}
}
},
columns: [{ field: "id", title: "ID", width: "100px" },
{ field: "Current_Time", title: "Time of Request", template: '#= kendo.toString(kendo.parseDate(Current_Time), "dd/MM/yyyy h:mm")#' },
{ field: "Selected_Time", title: "Scheduled Time" , template: '#= Selected_Time+" UTC" #'},
{ field: "Description" },
{ command: "destroy", width: "100px" }]
};