views:

309

answers:

1

this was for an old computer class project which I am over with and now am wondering if there was a better way of doing things .

we used to program an appointment.sh program where I solved the comparing time using an algorithm which converts time to a certain number you can compare today and tomorrow and of course what happens is it computes that tomorrow is greater and it's not today and you can schedule appointments based on whether or not the day/ hour is taken by comparing the said converted time.

i was wondering if there's an OS command to tell time with bash in linux? thanks!

+6  A: 

date tells you the current time. You may use command line parameters to specify a format, see man date.

For example for a UNIX timestamp (numbers you can easily compare), you can call date +%s.

ypnos
Of course it does, how logical :-) By rights, time should tell you the current date (don't worry, I know what time really does, I'm just kidding).
paxdiablo
Heh. Every second time I'm interested in the current time, I use the wrong command.
ypnos
+1 for for date +%s, you just beat me.
paxdiablo
Since it is a question for Linux, the answer is good. Note, though, that %s is a GNU extension to the 'date' command - not always applicable elsewhere (not on Solaris 10 or POSIX, but HP-UX 11.23 and AIX 5.3 do support it). I have a trivial command, systime, that does the job - now unnecessary.
Jonathan Leffler