9

I am trying to display only the current time using "date", not all that information Day, Month, Year etc.. , only the current time.

i.e.:

13:45 or 1:45pm

Any ideas?

1
  • This site works best when there's one question per post, please ask your question about time since reboot as a new one, thanks! Aug 21, 2013 at 22:07

5 Answers 5

19
date +%R

will show you the 24 hour time, and

date +%r

will show you the time in 12 hour format. date +%H:%I also works.

Check out the "Conversion Specifications" in the manpage for more variables to pick and choose.

4
  • Do I still have to repost the other question or an OP will repost it for me ? Aug 21, 2013 at 22:13
  • Go ahead and post it! Aug 21, 2013 at 22:14
  • worth saying that while %R is like %H:%M, %r is like %I:%M:%S. So the 12h version of %R is %I:%M%p. %H:%I instead looks wrong to me (it gives you hour in 24h and hour in 12h).
    – Cubiq
    Aug 21, 2013 at 22:20
  • 1
    date +%T in case you want seconds as well
    – Jay
    Dec 5, 2019 at 14:32
4

Current time 24h format:

date +%R

Current time 12h format with AM/PM:

date +%I:%M%p
4
date +%H:%M 

for 13:45

date +%H:%M #(if you don't write these : it is shown as for exmp. 0145)

for 01:45

"uptime" 

will tell how long the system has been running (along with other information) check man entry for uptime

1
  • It is not 1:45 it is 01:45, I edited post
    – france1
    Jul 29, 2021 at 7:58
2

I use this:

date +%T

for nanoseconds use this:

date +%T.%N

Example outputs:

$ date +%T
19:23:34
$ date +%T.%N
19:23:38.780062589
0

last displays info about recent logins. See http://linux.about.com/library/cmd/blcmdl1_last.htm for more info about it. I think it can show shutdowns too. For the time try date +%r. See http://linux.about.com/od/commands/l/blcmdl1_date.htm for more info on date.

5
  • I've asked the OP to repost that as a new question, when he does please post this there and then remove it from here, thanks! Aug 21, 2013 at 22:09
  • @JorgeCastro thanks. Didn't know about that. I am newbie in linux, and I am trying to learn it and this seems the only place where I can do this. Aug 21, 2013 at 22:10
  • No worries, keep on rocking! Aug 21, 2013 at 22:11
  • Will do... Awaiting new question...
    – Erresen
    Aug 21, 2013 at 22:17
  • @JamesCrawshaw I've posted new question here askubuntu.com/questions/335592/… Aug 21, 2013 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .