python中获取主机名和当前时间
来源:互联网 发布:射雕同人之悦与君知 编辑:程序博客网 时间:2024/06/08 00:00
1.获取主机名
import socket
hostName = socket.gethostname()
2.获取当前时间
import time
print time.time()
显示的当前时间的时间戳,如1312458498.031
用time.localtime()方法,格式化时间戳为本地时间
time.localtime(time.time())
输出结果为:
time.struct_time(tm_year=2011, tm_mon=8, tm_mday=4, tm_hour=19, tm_min=50, tm_sec=20, tm_wday=3, tm_yday=216, tm_isdst=0)
用time.strftime()方法,将其格式化为想要的结果:
time.strftime('%Y-%m-%d', time.localtime(time.time()))
输出结果为:2011-08-04
python中常用的时间日期格式化符号:
%y 两位数的年份表示(00-99)
%Y 四位数的年份表示(000-9999)
%m 月份(01-12)
%d 月内中的一天(0-31)
%H 24小时制小时数(0-23)
%I 12小时制小时数(01-12)
%M 分钟数(00=59)
%S 秒(00-59)
- python中获取主机名和当前时间
- python获取当前时间和前一天时间
- python 获取当前时间
- Python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- Python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- python获取当前时间
- Python获取当前时间
- Python获取当前时间
- Python获取当前时间
- python 获取当前时间
- python 获取当前时间
- python 获取当前时间
- if_changed_rule/cc_o_c/any-prereq/arg-check
- 关于WindowsXP
- DSP的Gel作用
- [转]解决PowerDesigner 相同字段名字
- 树状数组求逆序数
- python中获取主机名和当前时间
- listbox bind datasource, refresh data
- CodeForces 101D
- H263编解码在VS2005中结合opencv2.2的测试
- VirtualBox命令
- android-View实现游戏连连看
- 【dos BAT】关于DOS的批处理学习过程
- HDU 3724 Trie 树
- dirname $0