How To Print Current Date and Time In Linux and Windows From Command Line?
Getting current date time information is very different for different systems and programming languages. We will look this simple but big issue for vast majority of operating systems and programming languages.
We can date information from GUI panel clock but we will look for command line. We will issue date command to get current date and time. Linux date format have 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 date according to locale settings
$ date +%D
Windows date function which is provided by DOS operating system is very simple and lean. We only set or get date with date function
Python is a scripting language and to get current date time information python function in a code file can be used. Alternative is python interpreter. In this example we will use interpreter.
from datetime import datetime
now.strftime("%A, %d. %B %Y %I:%M%p")
We can get time information with %I:%M format string parameters.
We get get year, month and day as string like below