Getting current date-time information is very different for different systems and programming languages. We will look at this simple but big issue for the vast majority of operating systems and programming languages.
We can date information from the GUI panel clock but we will look for the command line. We will issue date command to get the current date and time. Linux date format has a lot of options. Alternatively, we can call these as Unix date or bash date examples.
Only Hour and Minute
We can provide parameters to get only time partition from date command.
$ date +%H:%M
Year Month Day Format
We can get current year month day like below
$ date +%Y_%m_%d
We can use ready to use parameters like +%F which will list year-month-day
$ date +%F
We can use +%D to get a date according to locale settings
$ date +%D
Display Date and Time In Windows Command Line
Windows operating system provides
time commands in order to print and set current date and time. After issuing the command date and time the current date and time will be displayed and then we will be asked for a new date and time. We can skip this just by pressing Enter or simply do not entering any value.
> date > time
Python Datetime Module and Functions
Python is a scripting language and to get current date time information python function in a code file can be used. An alternative is python interpreter. In this example, we will use an interpreter.
from datetime import datetime now=datetime.now() now.strftime("%A, %d. %B %Y %I:%M%p")
We can get time information with %I:%M format string parameters.
We get the year, month and day as a string like below