There are several ways to print information about the Linux command line date command in Python:
Method 1: Directly call the Linux command output, also can print the host name;
[email protected] tmp]# cat 1.py
#!/usr/bin/python
Import Os,commands
hostname = commands.getoutput (' hostname ')
Date = Commands.getoutput (' Date ')
Print hostname
Print Date
[[email protected] tmp]# python 1.py
host74
Thursday, May 25, 2017 16:05:16 CST
Method 2: The same as the result of method 1 execution;
[email protected] tmp]# cat 2.py
#!/usr/bin/python
Import OS
Os.system ("date")
[[email protected] tmp]# python 2.py
Thursday, May 25, 2017 16:06:39 CST
Method 3: Using the time Module CTime () display format looks less intuitive;
[email protected] tmp]# cat 2.py
#!/usr/bin/python
Import time
Print Time.ctime ()
[[email protected] tmp]# python 2.py
Thu May 25 16:05:50 2017
Method 4: Using the time module, according to the date of month and day display, more intuitive;
[email protected] tmp]# cat 2.py
#!/usr/bin/python
Import time
Print Time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
[[email protected] tmp]# python 2.py
2017-05-25 16:06:03
This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1929464
Print output date information in Python