How To Print Current Date and Time In Linux and Windows From Command Line? – POFTUT

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 at this simple but big issue for the vast majority of operating systems and programming languages.

Linux/FreeBSD/Unix

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.

Linux FreeBSD Unix date and time with Different Formats

Linux FreeBSD Unix date and time with Different Formats

Only Hour and Minute

We can provide parameters to get only time partition from date command.

Year Month Day Format

We can get current year month day like below

Year-Month-Day Format

We can use ready to use parameters like +%F which will list year-month-day

Month/Day/Year Format

We can use +%D to get a date according to locale settings

Display Date and Time In Windows Command Line

Windows operating system provides date and 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.

Display Date and Time In Windows Command Line

Display Date and Time In Windows Command Line

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.

LEARN MORE  How To Install and Use OpenSSL Library In Python Applications?

Python Datetime Module and Functions

Python Datetime Module and Functions

We can get time information with %I:%M format string parameters.

We get the year, month and day as a string like below

Python Datetime Module and Functions

Python Datetime Module and Functions

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)