import datetime
d1 = datetime.datetime.strptime('2015-03-05  17:41:20', '%Y-%m-%d %H:%M:%S')
d2 = datetime.datetime.strptime('2015-03-02 17:41:20', '%Y-%m-%d %H:%M:%S')

if d1>d2:
  print 'd1比较大'

else:
  print 'd2比较大'

来源: https://www.cnblogs.com/cssdongl/p/6729120.html

其中 strptime('2015-03-05  17:41:20', '%Y-%m-%d %H:%M:%S') 标红处的识别组合可以自定义修改

如 strptime('2015-03-05---17:41:20', '%Y-%m-%d---%H:%M:%S') 根据要识别的日期格式去修改即可

后记:(这个方法还可以计算间隔多少天)

获取当前时间的方法见 https://www.cnblogs.com/kaibindirver/p/12312357.html

python 时间对比的更多相关文章

  1. python init 方法 与 sql语句当前时间对比

    def init(self,cr): tools.sql.drop_view_if_exists(cr, 'custrom_product_infomation_report') cr.execute ...

  2. python编辑器对比和推荐

    python编辑器对比和推荐   我先给一个初步的表格吧,大家如果有什么意见,或有补充,欢迎提出.有些我没有用过,先不写了.以下是我使用过的python IDE: 除了PythonWin, Visua ...

  3. 浅谈Python时间模块

    浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...

  4. python时间处理之datetime

    python时间处理之datetime 标签: pythondateimportstringc 2012-09-12 23:21 20910人阅读 评论(0) 收藏 举报  分类: Python系列( ...

  5. python 时间字符串与日期转化

    python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...

  6. python时间日期字符串各种

    python时间日期字符串各种 第一种 字符串转换成各种日期 time 库 # -*- coding: utf-8 -*- import time, datetime # 字符类型的时间 tss1 = ...

  7. python性能对比

    python性能对比之items #1 #-*- coding:utf8-*- import datetime road_nodes = {} for i in range(5000000): roa ...

  8. Python 时间日历类型

    # 时间日历 # time模块 # 提供了处理时间和表示之间转换的功能 # 获取当前时间戳 # 概念 # 从0时区的1970年1月1日0时0分0秒, 到所给定日期时间的秒数 # 浮点数 # 获取方式 ...

  9. Python时间与日期操作(datetime、time、calendar)

    相关模块 模块 说明 time time是一个仅包含与日期和时间相关的函数和常量的模块,在本模块中定义了C/C++编写的几个类.例如,struct_time类 datetime datetime是一个 ...

随机推荐

  1. 属性 Attribute

    一.创建属性 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor, AllowMultiple = true, ...

  2. DevExpress WPF v19.2图表图形控件功能增强?速速种草

    通过DevExpress WPF Controls,你能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案. 无论是Office办公软件的衍 ...

  3. Django 反向查找(related_name)

    先定义两个模型,一个是A,一个是B,是一对多的类型 class A(models.Model): name= models.CharField('名称', max_length=32) class B ...

  4. selenium driver版本和Chrome浏览器版本对应关系

    ChromeDriver v2.41 (2018-07-27) ---- Chrome v67-69ChromeDriver v2.40 (2018-06-07) ---- Chrome v66-68 ...

  5. Codeforces Round #539 (Div. 1) 1109F. Sasha and Algorithm of Silence's Sounds LCT+线段树 (two pointers)

    题解请看 Felix-Lee的CSDN博客 写的很好,不过最后不用判断最小值是不是1,因为[i,i]只有一个点,一定满足条件,最小值一定是1. CODE 写完就A,刺激. #include <b ...

  6. date对象获取get

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 为什么用到springboot?

  8. 1628:X-factor Chain

    1628:X-factor Chain 时间限制: 1000 ms         内存限制: 524288 KB提交数: 122     通过数: 68 [题目描述] 原题来自 POJ 3421 输 ...

  9. jacky解读麻省理工《计算机科学与Python编程导论》第1集

    文:@数据分析-jacky(朱元禄) (一)导言 本课程讲的中心思想就是五个字:计算机思维 Python只是辅助工具,是辅助大家理解计算机思维,仅此而已 急功近利是人性,适得其反是结果:我们看到有很多 ...

  10. c 判断是否为 字母或数字(iswalnum example)

    #include <stdio.h> #include <wctype.h> int main () { int i; wchar_t str[] = L"c3p.o ...