Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current time in seconds since the Epoch on Linux, Bash

I need something simple like date, but in seconds since 1970 instead of the current date, hours, minutes, and seconds.

date doesn't seem to offer that option. Is there an easy way?

like image 662
n-alexander Avatar asked Jul 07 '09 14:07

n-alexander


People also ask

How do you get epoch time in seconds?

long epoch = System.currentTimeMillis()/1000; Returns epoch in seconds.

How do I get current epoch time in shell?

how can I get the current standard epoch time (seconds from 1970) in a shell script? I know I could do this with a bit of perl of even c++ but i want to do it in Bourne shell..... date +%s should give you that. date +%s should give you that.

How do I convert time to seconds in Linux?

time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). If t is non-NULL, the return value is also stored in the memory pointed to by t.


1 Answers

This should work:

date +%s 
like image 95
Steef Avatar answered Sep 28 '22 20:09

Steef