Tuesday, May 3, 2011

Seconds since the Unix epoch in C#/java, the same output of Time() in PHP

in Php, there is one Time() function, Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
  in C#, there is no built-in function to return seconds since UNix epoch, here is the code snippet to return the same thing

int t = (int)DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

In Java, there is one standard function, System.currentTimeMillis(),which measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

System.currentTimeMillis()/1000

No comments:

 
Locations of visitors to this page