0

I have a concept for a special albeit simple kind of clock that would display the number of seconds since a certain point in time (which would never change). What would be the best way of storing, incrementing and displaying this persistent value?

Bobe
  • 2,040
  • 8
  • 29
  • 49

2 Answers2

1

If the start point never changes, you only need to save that. Concept wise, that would be the same as Unix time.

Simply get the current system time and calculate the difference to the beginning of your epoch.

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • The [time](http://de3.php.net/manual/en/function.time.php) function returns the elapsed seconds since 01-01-1970 00:00:00. – Femaref Jan 10 '13 at 15:40
  • It's always that date. You could define your own, but then you wouldn't be able to use the date related functions as they all work on the unix epoch definition. I strongly advise against doing anything of that sort. – Femaref Jan 10 '13 at 15:44
  • Well I suppose I could use that and then just add the extra digits before it since they wouldn't change anyway. – Bobe Jan 10 '13 at 15:49
  • Then you will not be able to use any date related function, neither would you be able to properly store them in a database. If you do it, you will open a can of worms. – Femaref Jan 10 '13 at 15:51
  • All I want to do is display it as text, nothing more. The extra digits would just be hard-coded HTML. Does it actually have to be stored? Doesn't it just get generated by the server? – Bobe Jan 10 '13 at 15:53
1

This was done via the Unix epoch. You would just need to create your own version of the epoch perhaps BobeEpoch. You could store this value somewhere that your application can retrieve it, then you would invoke the current system time. Once you had the current system time you would subtract this value from BobeEpoch and display that to the user.

Woot4Moo
  • 23,987
  • 16
  • 94
  • 151