a='2018-03-26 17:20:11'

>>> print time.strftime("%Y%m%d", a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not str
>>> time.localtime()
time.struct_time(tm_year=2018, tm_mon=5, tm_mday=17, tm_hour=20, tm_min=26, tm_sec=41, tm_wday=3, tm_yday=137, tm_isdst=0)

>>> b=time.strptime(a,"%Y-%m-%d %H:%M:%S")
>>> print time.strftime("%Y%m%d", b)
20180326

python time 时间处理的更多相关文章

  1. python语法------时间函数

    1.导入函数库: import time 获取格式化的时间 你可以根据需求选取各种格式,但是最简单的获取可读的时间模式的函数是asctime(): #!/usr/bin/python # -*- co ...

  2. python中时间的基本使用

    格式化日期 我们可以使用 time 模块的 strftime 方法来格式化日期,: time.strftime(format[, t]) #!/usr/bin/python # -*- coding: ...

  3. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  4. python中时间格式

    问题:通过MySQLdb查询datetime字段,然后通过浏览器显示出来,得到的格式是:         'Thu, 19 Feb 2009 16:00:07 GMT'   (http呈现出来的格式) ...

  5. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  6. Python日期时间函数处理

    所有日期.时间的 api 都在datetime模块内. 1 日期的格式化输出 datetime => string import datetime now = datetime.datetime ...

  7. Python datetime时间日期处理

    在处理微博数据的时候,经常会遇到对时间数据的处理,于是决定开始去一步一步的总结下Python关于时间的常见处理,主要以参考Python的官方文档为主,结合实例.接下来会一步一步更新,敬请期待

  8. python 日期 & 时间

    1. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 2. 时间间隔是以秒为单位的浮点小数. 3. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长 ...

  9. Python日期时间Date/Time

    Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...

  10. Python入门 - 时间处理

    本讲主要介绍python时间处理方式,比如获取当前的时间: import time ftime = time.strftime("%Y年%m月%d日%H点%M分%S秒", time ...

随机推荐

  1. 十一、持久层框架(MyBatis)

    一.基于注解方式的CRUD 把xml方式的CRUD修改为注解方式 之前在xml中配置,是在<mapper></mapper>标签下写CRUD <mapper namesp ...

  2. C++ string::size_type

    从逻辑上讲,size()成员函数应该似乎返回整型数值,但事实上,size操作返回是string::size_type类型的值.string类类型和其他许多库类型都定义了一些配套类型(companion ...

  3. 【转】Code First 属性详解

    下面解释每个配置的作用 Table :用于指定生成表的表名.架构信息. Column :用于指定生成数据表的列信息,如列名.数据类型.顺序等. Key :用于指定任何名称的属性作为主键列并且默认将此列 ...

  4. WinForm之窗体应用程序

    WinForm之窗体应用程序 基本简单数据库操作(增删改查) using System; using System.Collections.Generic; using System.Windows. ...

  5. ubuntu12下安装eclipse+pydev +1搜索命令+kill指定进程

    sudo apt-get install eclipse 下载pydev for eclipse 2.8,如果是jre6 解压. sudo nautilus 复制相应的文件夹到/usr/share/e ...

  6. QuickStart系列:docker部署之PostgreSQL

    mysql --> mariadb --> postgresql 官网简介 https://www.postgresql.org/ 使用的镜像名称 centos/postgresql-96 ...

  7. js 判断某个元素是否隐藏或显示

    //判断某个元素是否显示 true:是 false:不是 var isVisible = $('#myDiv').is(':visible'); //判断某个元素是否隐藏 true:是 false:不 ...

  8. 理解JavaScript的运行

    JavaScript可以运行在head和body标签中! HTML的脚本必须放在<script></script>标签中间! 浏览器会解释并执行位于script标签中的脚本! ...

  9. L1-053 电子汪

    据说汪星人的智商能达到人类 4 岁儿童的水平,更有些聪明汪会做加法计算.比如你在地上放两堆小球,分别有 1 只球和 2 只球,聪明汪就会用“汪!汪!汪!”表示 1 加 2 的结果是 3. 本题要求你为 ...

  10. Centos7部署hadoop 3

    一:ssh免密登录: 1)vim /etc/ssh/sshd_config去掉注释或添加 RSAAuthentcation yes PubkeyAuthentication yes # Authent ...