time模块提供各种操作时间的函数
  说明:一般有两种表示时间的方式:
       第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的
       第二种以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同
    year (four digits, e.g. 1998)
    month (1-12)
    day (1-31)
    hours (0-23)
    minutes (0-59)
    seconds (0-59)
    weekday (0-6, Monday is 0)
    Julian day (day in the year, 1-366)

1.判断今年是否为闰年。

闰年定义

import time
thisYear = time.localtime()[0]
print time.localtime()
if thisYear%4==0 and thisYear%100!=0:
print "This year is not a typical Year"
else:
print "This year is a typical year."

2.任意输入日期,判断这是该年的第几天

year=0
month=0
date=0
year = int(raw_input("Please input the year>"))
month = int(raw_input("Please input the month>"))
date = int(raw_input("Please input the date>"))
day=date
normal=[31,28,31,30,31,30,31,31,30,31,30,31]
run=[31,29,31,30,31,30,31,31,30,31,30,31]
if year%4==0 and year%100!=0 or year%400==0:
  list=run
else:
  list=normal

for i in list[:month-1]:
  day=i+day
print day

python中常见的日期换算的更多相关文章

  1. python中常见的日期处理方法

    今天:today = datetime.date.today() 昨天:yesterday = today - datetime.timedelta(days=1) 上个月:last_month = ...

  2. Python中常见字符串去除空格的方法总结

    Python中常见字符串去除空格的方法总结 1:strip()方法,去除字符串开头或者结尾的空格>>> a = " a b c ">>> a.s ...

  3. Python中常见的异常总结

    Python中常见的异常总结 当Python检测到一个错误时,解释器就会指出当前流已经无法继续执行下去,这时候就出现了异常. 一.异常错误    a.语法错误     错误一:     if     ...

  4. python中常见的错误

    python中常见的错误   1.IndentationError: unindent does not match any outer indentation leve 众所周知,Python语法要 ...

  5. python中常见的报错信息

    python中常见的报错信息 在运行程序时常会遇到报错提示,报错的信息会提示是哪个方向错的,从而帮助你定位问题: 搜集了一些python最重要的内建异常类名: AttributeError:属性错误, ...

  6. Python中常见的报错名称

    Python中常见的报错名称 1.SyntaxError 语法错误.看看是否用Python关键字命名变量,有没有使用中文符号,运算符.逻辑运算符等符号是不是使用不规范. 2.IndentationEr ...

  7. Python中对时间日期的处理方法简单汇总

    这篇文章主要介绍了Python实用日期时间处理方法汇总,本文讲解了获取当前datetime.获取当天date.获取明天/前N天.获取当天开始和结束时间(00:00:00 23:59:59).获取两个d ...

  8. 解决 python 中,时间日期不能序列化的问题

    在python 中, 你在数据库娶到了数据中如果含有时间日期,那么你在向前端作为json对象传递的时候呢,就会报错.大致如下: TypeError: datetime.datetime(2017, 1 ...

  9. Python 中常见错误总结

    IndentationError: unexpected indent Python 中强制缩进,, IndentationError: unexpected indent 缩进错误 这类错误非常常见 ...

随机推荐

  1. Null和Undefined类型

    Null和Undefined类型都只有唯一的特殊值,即null和undefined.不过null是关键字而undefined不是. JavaScript把两者定义为相等的,如下代码可以验证: aler ...

  2. 【转】 通过VMLibrary在client partition上安装AIX全程实录

    现场实录,应该对新手有所帮助,因为本人就是新手...最近一段时间跟Linux无缘,都是在和PowerVM打交道,博文更新慢,不赖我,哈哈本文参考链接:AIX Migration with File-B ...

  3. 利用jdk中工具完成Java程序监控方法记录

    转载加自己整理的部分内容,转载自:http://jiajun.iteye.com/blog/810150 记录下JConsole使用方法 一.JConsole是什么    从Java 5开始 引入了 ...

  4. Python文件操作——逐行插入内容

    需求: 分析: 1)打开文件 2)readlines() 读文件(按行读) --> 拿到文件内容 data 3)循环遍历 data 的每行,在每行后面进行拼接要插入的内容 4)往新文件里写 代码 ...

  5. 目标是:互联网方向的Java开发工程师

    我们需要这样完美的你: --师出名门:应届统招本科及以上学历,计算机相关专业: --技艺超群:熟悉JAVA面向对象编程, J2EE体系结构,熟悉Struts2.Spring.Ibtais.Memcac ...

  6. 非Linux环境下调用sh命令

    方法一:把cygwin的bin配置到环境变量里,这样做了以后在cmd.exe里也可以使用linux的命令 def exe_command(command): p = subprocess.Popen( ...

  7. Python lxml 使用

    lxml,是python中用来处理xml和html的功能最丰富和易用的库 from lxml import etree from lxml import html h = ''' <html&g ...

  8. hive bin下的进入beeline 命令行和hive有什么不同?

    Hive 0.11中引入的HiveServer2有一个自己的CLI叫Beeline. HiveCLI现在已经过时,与Beeline相比,其缺少多用户.安全和其他与HiveServer2兼容的特性. 从 ...

  9. Docker基础入门实践

    原文地址 基本概念 Docker三个基本概念 镜像(Image) 容器(Container) 仓库(Repository) 镜像 镜像可以理解为只读模板,如包含一个centos操作系统环境 容器 Do ...

  10. Kattis - convexpolygonarea 【数学】

    题意 给出一系列点,求这个多边形面积 思路 向量叉积 AC代码 #include <cstdio> #include <cstring> #include <ctype. ...