Question by
daviddickball · Sep 13, 2015 at 04:56 PM ·
datetimeconvertingtimespan
Formatting a timespan into a relative date in JavaScript
Hi dudes, I want to save the DateTime when a user logs on when they start playing, then the next time do a calculation to find the difference, and display this in a friendly format e.g. 2 days ago, 3 hours ago, 4 mins ago etc.
I've seen many examples of how to do this using c#, but not in JavaScript, and every example has failed me.
The challenges I'm stuck on - 1) converting a string saved in playerPrefs back into a date. I've seen Convert.ToInt64() used, but this doesn't work for me. 2) Converting the timespan into a friendly format. I've seen DateTime.Days and .Hours used, but these won't work for me in JavaScript.
Comment