To do that, simply type in the following command in the terminal: date +%sĪt the time of writing this, I got the output as follows: :~$ date +%s In other words, you will be able to know how many seconds have elapsed since 1 January 1970 00:00:00 UTC to the present time. Calculate the time from epoch timeĪnother interesting use of the date command is calculating the time in seconds since epoch time or Unix time. And, the right after the flag -d, you type the date you want to identify. Here, %A helps to specify the date, you can change it to %B to display the month name as well. The output for this when you type it in should look like: :~$ date -d "" +"%A" If you have a particular date but want to identify the day of the week, you can do that easily by typing in: date -d "" +"%A"
Use date command to identify a specific day Similarly, you can use “tomorrow” / “last-year” / “next-year” / “next-month” and so on.
Suppose you want to know what the date was last week, you can do that using the date command.Īll you have to do is type in: date -d last-week Use date command to display a time/date for past/future This is how it should look like when you scroll down through the instructions after the help command: 3. You shall find a list of sequences similar in addition to all the information associated with the date command when you type in this: date -help When you do this, expect a similar output like this: :~$ date +"Week: %V Year: %y" In the command above, I added a string after + inside the inverted commas and then pass some pre-built sequences like %A or %B to control what you want to display. If you want to just display the current time in Linux, use this: date +%TĪnother example of the command to show the control over output format: date +"Weekday: %A Month: %B" Just like I mentioned above, you can control what you want in the output using the date command. Let us take a quick peek at the available formatting options. In addition to these use-cases, you can also control the output and use the formatting options available. So, when you get an invalid date error while using the date command, simply check the date format of your input.įor this, you get an output that should look like: :~$ date -d "" So, if you type something in a different order, you will encounter an error that should say this: :~$ date -d "25-08-1996" It is worth noting that the format for the input is YYYY-MM-DD. Suppose, you have a specific date but you want to display the weekday for that date, you need to specify the date using the -d flag as: date -d "" Here’s how it looks with the input and output: :~$ dateĪs you can see, it also shows the time zone along with the system time. To start with, you just need to enter the command “date” to display the date and time. Display the current date and time in Linux I have included some examples below which should give you some clarity on what I explained here. Here the option is essentially a flag like -d, – debug, etc which I’ll discuss in the later section of this article.Īnd, the format lets you control the output by adding your own string and specify the values you want in the output. Here’s the syntax of the date command: date In this article, we take a look at the date command in detail and what you can do with it using some examples. Yes, you can do a couple more things using the date command like identifying a week or day from a date, calculating the time from epoch to a specified time, and a few more variations.’ The date command in Linux is the simplest way to display the current time and date in Linux.īut, there’s more to it than meets the eye.