Imprima hora da época em diferentes idiomas
Pergunta
Como você deve saber, hoje à noite, exatamente às 23:31:30 UTC, o horário da Epoch chegará ao 1234567890! Hurra!
Uma maneira de assistir a época da época é usar Perl:
perl -le 'while(true){print time();sleep 1;}'
Você pode fazer o mesmo em outra linguagem de programação?
Solução
isto local está nos meus favoritos e tem muitas respostas para isso
Outras dicas
Python One-line:
python -c "while True: import time;print time.time();time.sleep(1)"
script de shell:
while :; do printf "%s\r" $(date +%s); sleep 1; done
Pitão:
import time
import sys
while True:
sys.stdout.write("%d\r" % time.time())
sys.stdout.flush()
time.sleep(1)
PHP uma linha
php -r 'while(true) { echo time(), "\n"; sleep(1);}'
ZSH - Shell Advanced Unix:
zmodload zsh/datetime && while true; do print $EPOCHSECONDS ; sleep 1; done
Este seria o mesmo código em C#:
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
while (true)
{
Console.WriteLine((int)(DateTime.UtcNow - epoch).TotalSeconds);
Thread.Sleep(1000);
}
E como Tehvan disse, é o atual Tempo, não o horário da "época"
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) {
}
}
}
}
Java:
System.out.println((new java.util.Date(0)).toString());
Essa é a época :) ... o atual o tempo seria:
System.out.println((new java.util.Date()).toString());
Para que a quantidade de milissegundos aprovados desde a época, faça:
System.out.println("" + (new java.util.Date()).getTime());
Mais Perl:
perl -MAnyEvent -MDateTime -E 'my $cv = AE::cv; my $w = AE::timer 0, 1, sub { say DateTime->now->epoch }; $cv->wait'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow