You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm storing my dates in a database that's in milliseconds, but I want to be able to show and sort it in a format of date : time. Is it possible to keep the data that's in the table in milliseconds but display it in the correct format?
This is how I'm currently doing it:
`const columns = React.useMemo(
() => [
{
Header: 'Date',
accessor: "backup_date_time", // accessor is the "key" in the data
className: "backup_log_device_name_col",
headerClassName:"backup_log_table_header",
Cell: c => {getLocalDate(new Date(c.value))}
},
{
Header: 'Error Message',
accessor: 'message', // accessor is the "key" in the data
className: "backup_log_device_name_col",
headerClassName:"backup_log_table_header",
},
],
[]
)
function getLocalDate(t){
let z = t.getTimezoneOffset() * 60 * 1000;
let tLocal = t-z
tLocal = new Date(tLocal)
let iso = tLocal.toISOString()
iso = iso.split(".")[0]
iso = iso.replace('T', ' ')
return iso
}
Is this the correct way of doing it? Will it work the way I've coded it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm storing my dates in a database that's in milliseconds, but I want to be able to show and sort it in a format of date : time. Is it possible to keep the data that's in the table in milliseconds but display it in the correct format?
This is how I'm currently doing it:
`const columns = React.useMemo(
() => [
{
Header: 'Date',
accessor: "backup_date_time", // accessor is the "key" in the data
className: "backup_log_device_name_col",
headerClassName:"backup_log_table_header",
Cell: c => {getLocalDate(new Date(c.value))}
},
{
Header: 'Error Message',
accessor: 'message', // accessor is the "key" in the data
className: "backup_log_device_name_col",
headerClassName:"backup_log_table_header",
},
],
[]
)
function getLocalDate(t){
let z = t.getTimezoneOffset() * 60 * 1000;
let tLocal = t-z
tLocal = new Date(tLocal)
let iso = tLocal.toISOString()
iso = iso.split(".")[0]
iso = iso.replace('T', ' ')
return iso
}
Is this the correct way of doing it? Will it work the way I've coded it?
`
Beta Was this translation helpful? Give feedback.
All reactions