Show date from Unix timestamp field


#1

I have created a screen to manage and study values from the users and I would like to show the field that is stored as a Unix timestamp but to be display as a regular date.

How could I do this?


#2

You need to write a value transformer script which transform unix time to date format you prefer.

Here’s article about this: https://coderrocketfuel.com/article/convert-a-unix-timestamp-to-a-date-in-vanilla-javascript

Youll find more from google ”unix time to date javascript”


#3

Thank you. I have gone into the script section and try to create the script by myself but I believe there are a couple of details I need to change to make it work:

const unixTimestamp = this.props.appActions.getDataSheet(‘allScores’)
const milliseconds = unixTimestamp * 1000
const dateObject = new Date(milliseconds)
const humanDateFormat = dateObject.toLocaleString()
return input;

In the first line I try to create the constant with the value of the Timestamp in my database, which is the field “date” in the dataSheet “allScores”. Using the snippets I wrote that accessing the dataSheet “allScores” but I believe it would be necessary to specify the field “date” which is the one that contains the Timestamp.

In the last line, I believe I would need to link somehow the “input” to the constant humanDateFormat. I don’t know if it would be just “input = humanDateFormat” before the “return input”.


#4

Hi,

This is how I’d do it in a list.

If you somehow need to fetch the Data sheet manually in the script then you need to find the correct data sheet row and then refer to “field”. E.g. like this:

this.props.appActions.getDataSheet(‘allScores’).items[0].columnName


#5

It is working now. Thank you!


#6

One question. The script works perfectly but it shows two hours less than my timezone. How could I modify it to show exactly my timezone? (I am in Spain).


#7

let ts = new Date(input);

let spainTime = ts.toLocaleString(“en-US”, {timeZone: “Spain/Madrid”});


#8

Thank you so much for your answer. It gave me a timeZone error but I wrote “Europe/Madrid” instead of “Spain/Madrid” and it worked. Thank you!