As you may know, tonight, at exactly 23:31:30 UTC, Epoch Time will reach 1234567890! Hurray!
One way of watching epoch time is by using Perl:
perl -le 'while(true){print time();sleep 1;}'
Can you do the same in another programming language?
As you may know, tonight, at exactly 23:31:30 UTC, Epoch Time will reach 1234567890! Hurray!
One way of watching epoch time is by using Perl:
perl -le 'while(true){print time();sleep 1;}'
Can you do the same in another programming language?
java:
System.out.println((new java.util.Date(0)).toString());
That's the epoch :) ... the current time would be:
System.out.println((new java.util.Date()).toString());
For getting the amount of milliseconds passed since the epoch, do:
System.out.println("" + (new java.util.Date()).getTime());
This would be the same code in c#:
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
while (true)
{
Console.WriteLine((int)(DateTime.UtcNow - epoch).TotalSeconds);
Thread.Sleep(1000);
}
And like tehvan said, it's the current time, not "Epoch" time
Java
import java.util.Date;
public class EpochTime {
public static void main(String[] args) {
while (true) {
System.out.println(new Date().getTime() / 1000);
try {
Thread.sleep(1000);
}
catch (InterruptedException ignore) {
}
}
}
}
shell script:
while :; do printf "%s\r" $(date +%s); sleep 1; done
python:
import time
import sys
while True:
sys.stdout.write("%d\r" % time.time())
sys.stdout.flush()
time.sleep(1)
python one-line:
python -c "while True: import time;print time.time();time.sleep(1)"