How to merge api.clientside_callback and regular callback

Hi Team,

I have requirement, where I need to fetch the local/client timezone offset and show the stored db time in local /client timezone and use it in another callback returned to UI.

How can i convert the below Javascript code which is in clientside_callback to the regular callback as show in below.

app.clientside_callback(
“”"
function(id) {
const local_date_str = new Date().toLocaleString();
return “The current date and time is: " + local_date_str
}
“””,
Output(‘date-time-title’, ‘children’),
Input(‘date-time-title’, ‘id’),
)

@app.callback(
Output(“DB_time”, “children”),
Input(“local_time_zone”, “n_clicks”)
)
def return_db_time_according_to_local_timezone(_):
“”"
I would like to show the time which is stored in DB
to the local time zone in UI
“”"
pass

Help would be appreciated!

Hello @Sandeep,

I think the easiest way would be to send the data from the server not to a UI element, but to a dcc.Store that the clientside picks up and converts to local time.

@jinnyzor, If possible could you please share a piece of code or point to the document.
Thanks for the prompt response.

@Sandeep,

Sure, I’ll just do the time transfers:

#send data to client
@app.callback(
Output(‘timeStore’,’data’),
Input(‘getTime’,’n_clicks’)
)
def sendTime(n1):
     if n1>0:
          return date
     return dash.no_update

#clientside
app.clientside_callback(
“””function (d) {
    if (d) {
         return Date(d).toLocaleString()
    }
return window.dash_clientside.no_update
}”””,
Output(‘displayTime’,’children’),
Input(‘timeStore’,’data’)
)

Where timeStore is a dcc.Store and displayTime is a div.