Take the 2-minute tour ×

Is there a way to use unix date to print the number of seconds since epoch?

I'm open to using other standard shell commands if there is a way

(I'm using Solaris, so there isn't date "+"%s")


share|improve this question
Is perl (perl -e 'print localtime' ) not an acceptable answer? I can't think of how to do it with the date command. –  MJB Apr 7 '10 at 12:56
@MJB rather than 'print localtime', the comparable perl expression to "date +%s" would be "perl -e 'print time'" –  michael_n Jul 13 '12 at 7:45
probably should be considered a duplicate of stackoverflow.com/questions/2445198/… (but there are many duplicates of this question) –  michael_n Jul 13 '12 at 7:46
add comment

3 Answers

up vote 2 down vote accepted

Well, since this is a programming site, I would just compile something like:

#include <stdio.h>
#include <time.h>
int main (void) {
    printf ("%d\n",time(0));
    return 0;


share|improve this answer
add comment
perl -e 'print time'
share|improve this answer
add comment

you can try nawk,(but try to double confirm with the perl commands and see if they give the same results)

nawk "BEGIN{print srand}"
share|improve this answer
add comment

Your Answer


