Why do we need to calculate the time since 1970?

In most programming languages ​​or scripts, such as PHP or JavaScript, I came across a time function that tends to calculate time since 1970. For example, in javascript, if I use the getTime () or PHP function, time () returns an integer value.

In PHP.

code with <?php echo time(); ?>returns the integer value 1281694425, what explains the value returned by php? how and when is it useful?

the same in javascript getTime () has been returning a float value since 1970, as it says. using script in js

<script type="text/javascript">
var d=new Date();
document.write(d.getTime() + " milliseconds since 1970/01/01");
</script>

I want to know when this type of function is useful to use? and how do we use it?

PS: is it useful for calculating the time interval? or is it used to store the current timestamp?

+5
source share
3 answers

This gives you the seconds that have passed since January 1, 1970. This is useful for several reasons:

  • Sorting dates is as simple as sorting integers.
  • It’s easy to get the length of the interval, just do t1-t2, and again you get the difference in seconds.
  • No need to handle different date formats (for example, MM / DD / YY or DD / YY / MM): each programming language and each database supports integers.
+7
source

If you want to know the history of this time view, look at this: http://en.wikipedia.org/wiki/Unix_time .

+6
source

, , , . : -)

+1

All Articles