Timestamp conversion

Hi there,
I have read a lot about timestamp in the community I am just so confused about it.
When I set up 11:00 am (CEST) in my weweb, and push it to my xano, it saves it as 11:00 am probably UTC because when I retrieve the data it now displays 1 pm.
It’s a schedule in an object like this :
image

How should I proceed? I have been struggling for hours, nothing makes sense to me.

How exactly are you setting up the 11am in Weweb? By selecting a time in a date picker comportment? Could you also include a screenshot of Weweb?

yes just a simple time selector

In your example, the time itself isn’t related to a timezone because to do so, it would also need to include a date, which could be converted to an EPOCH Timestamp (https://www.epochconverter.com/). In your case, you don’t need to care about this. All you need to do is to convert the time to milliseconds. That way you’ll be able to store it in Xano (in milliseconds). And then, you’re going to have to re-convert it when included in Weweb.

Here’s how to convert it to milliseconds using Javascript:

// Extract the preview time from the context
const previewTime = context.item.data?.['preview'];

// Check if previewTime is not empty
if (previewTime) {
  // Split the time string into hours and minutes
  const [hours, minutes] = previewTime.split(':').map(Number);

  // Convert hours and minutes to milliseconds
  const hoursInMilliseconds = hours * 60 * 60 * 1000;
  const minutesInMilliseconds = minutes * 60 * 1000;

  // Calculate the total milliseconds
  const totalMilliseconds = hoursInMilliseconds + minutesInMilliseconds;

  return totalMilliseconds;
} else {
  // Return 0 if previewTime is empty
  return 0;
}

Here’s the code to reconvert it to a time “hh:mm” format (replace 39600000 by the milliseconds coming from Xano):

// Define the milliseconds value
const milliseconds = 39600000;

// Convert milliseconds to hours and minutes
const hours = Math.floor(milliseconds / (1000 * 60 * 60));
const minutes = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60));

// Format the result as "hh:mm"
const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;

// Return the formatted time
return formattedTime;

I hope this helps.

Thank you a lot, I am not sure, I have done everything right.

Basically, I am trying to let my users update their schedule.

I have saved a timestamp in my Xano, retrieved it, so I would like to display the current value, while allowing them to edit it and update it to my Xano.

It looks like I am getting a timestamp from Xano which I can edit to get the time, but as it comes as a number the formula I use doesn’t work when the user tries to select a different time as it comes as “text”.

I think I have made something simple hard, but I just can’t find a way to do it, I have tried your formula and thanks it works well, but don’t really know where and how to integrate it in this flow.

I have dates saved on my xano additionally to the time but from what I understood I shouldn’t

Change the openMorning and closeMorning column type to numbers instead of timestamp in Xano. That way it’ll return you back a number when fetching the API.

I’m working on a solution now. Thank you so much for your help! Converting to milliseconds was a crucial point I hadn’t considered.

I also appreciate you taking the time to write the code; I’ve been able to implement it successfully.

Thanks again for your assistance! :fire:

1 Like