So I have dates which comes back in an ISO style timestamp: 2022-01-29T18:01:52.477Z
It does not appear to recognize this and isn't formatting it:
const setDateFormat = {
type: 'date', format: 'dd/MM/yyyy'
}
<ColumnDirective headerText='Created On' field='CreatedOn' format={setDateFormat} width='80' />
How should I get this working? Thanks.
|
[app.js]
var data = [
{
OrderID: 10248,
CustomerID: 'VINET',
EmployeeID: 5,
OrderDate: new Date('2022-01-29T18:01:52.477Z'), // use DateObject value for date column
},
----
];
const setDateFormat = {
type: 'date',
format: 'dd/MM/yyyy',
};
const SyncGrid = () => {
return (
<div>
<GridComponent dataSource={data}>
---
<ColumnDirective
field="OrderDate"
headerText="Order Date"
width="130"
type="date"
format={setDateFormat}
/>
</ColumnsDirective>
</GridComponent>
</div>
);
};
|
I also need to output the hh:mm:ss of the date time. I try like below, but the time section comes incorrect.
I noticed, it works corretly, only when 'Z' - zulu character is removed the input date.
Could you help to show to display the dat and time correctly, when input date is in Zulu format ?
Hi Onur,
Thanks for contacting
Syncfusion support.
When converting UTC DateStriing into a Date object, it will be converted into the local timezone. This is the default behavior of Javascript.
|
|
In order to assist you further, kindly share the below details to proceed further.
Regards,
Rajapandiyan S
Here's what I have done to make this work, I use a valueAccessor which basically lets me set whatever I want. I think for your timezone in india you would use .toLocaleString('hi')
// Convert the grid action dates into dateTime
const setDateFormat = (field, data, column) => {
return new Date(data[field]).toLocaleDateString("en-US", {
timeZone: "UTC",
month: "short",
day: "numeric",
year: "numeric",
})
}
// Attach a valueAccessor property
<ColumnDirectiveheaderText"Action Date"
field="actionDate"
valueAccessor={setDateFormat}
width="150"
/>
Hi Onur,
You can use the value accessor method to show the values in a customized format.
But this is used only for display purposes, all the data actions like
filtering, sorting, etc., are performed with the data bound to the Grid. We can
convert the time before binding the data to the Grid. Kindly share the below
details to achieve this.
Regards,
Rajapandiyan S