Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

How to execute a function once in a day?

$
0
0

you can use the Javascript Date.now() function to get the amount of seconds that past since jan 1 1970 00:00 UTC.
http://www.unixtimestamp.com/

Save this value on first run some persistent memory.
ex. https://blog.nraboy.com/2014/12/use-ngstorage-angularjs-local-storage-needs/

every time afterwads when you open the app you compare the current value of your Date.now() with the stored value by distracting the stored value from the current value.Then you divide it by 86.400(seconds) and you have your days past since installation.

Some pseudo-code:

var now=Date.now();
var storage=$localStorage;
var checkDate=function(){
if(storage.initDate){
$scope.daysPast=Math.floor(now-storage.initDate);
}else{
storage.initDate=now;
}
}

Hope it helps.
Keep on hacking away...


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>