Page 1 of 1

How to log a timestamp ?

Posted: Thu Sep 12, 2013 5:22 pm
by Walter Lee6162535

Hi,

I am writing an app for early stroke signs for non-English speaking.
One feature I like is to log the timestamp when they hit a button so they can show the doctor later the time they suspect.

Any code sample ? example ? to save this in a label or something, so it can persist later when they arrive at the hospital and open the app again ?

I am very beginner, so the more code/example the better !

Thank you!

Walter


How to log a timestamp ?

Posted: Thu Sep 12, 2013 7:24 pm
by Kateryna Grynko

Hi Walter,

You can save timestamp in localStorage on button click, and then show it.

Examples:
1) To get timestamp, and save it run:
codelocalStorage.setItem('mytime',new Date().getTime());/code
2) To get timestamp value run:
codelocalStorage.getItem('mytime');/code
Or better you can save a local variable value in Label in appery UI. For any event choose setProperty action, for Label component select "read from local storage variable" where specify the variable name, such as in the example above - "mytime".


How to log a timestamp ?

Posted: Sat Sep 14, 2013 9:37 am
by Walter Lee6181771

Hi, Katya,

I followed the steps and make a new button to run JS below when clicked,

{
localStorage.setItem('mytime',new Date());

var timestamp = localStorage.getItem('mytime');
Appery('StroketimeLable').text((timestamp));
}

I can see the label has
"Sat Sep 14 2013 02:34:40 GMT-0700 (Pacific Daylight Time)"

timestamp !

Thank you!

So, this will stay and be seen again even the app was closed and later again when needed. It is used to record the stroke patient stroke timestamp and need to show the ER doctor later . So, this q.

Thank you!

Walter


How to log a timestamp ?

Posted: Sat Sep 14, 2013 4:40 pm
by Walter Lee6162535

I just tested and the timestamp will be lost going from this page to another.
Please help me to save it as a persistent data .
The more code example the better for me .
Thank you.


How to log a timestamp ?

Posted: Sat Sep 14, 2013 5:05 pm
by Igor

You could try to create new JS file. In JS file create new function with code which you posted above and call this function on button click event.


How to log a timestamp ?

Posted: Sat Sep 14, 2013 6:23 pm
by maxkatz

Just to add, local storage data is persisted between page navigation and also if you restart the browser.


How to log a timestamp ?

Posted: Sat Sep 14, 2013 11:22 pm
by Walter Lee6162535

thanks !
I figured it out.
I forgot to load it when page reload, so it did not show up.
It is persistent across the pages and restart !

Excellent !
Thank you !