python中常见的日期换算
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中常见的日期换算的更多相关文章
- python中常见的日期处理方法
今天:today = datetime.date.today() 昨天:yesterday = today - datetime.timedelta(days=1) 上个月:last_month = ...
- Python中常见字符串去除空格的方法总结
Python中常见字符串去除空格的方法总结 1:strip()方法,去除字符串开头或者结尾的空格>>> a = " a b c ">>> a.s ...
- Python中常见的异常总结
Python中常见的异常总结 当Python检测到一个错误时,解释器就会指出当前流已经无法继续执行下去,这时候就出现了异常. 一.异常错误 a.语法错误 错误一: if ...
- python中常见的错误
python中常见的错误 1.IndentationError: unindent does not match any outer indentation leve 众所周知,Python语法要 ...
- python中常见的报错信息
python中常见的报错信息 在运行程序时常会遇到报错提示,报错的信息会提示是哪个方向错的,从而帮助你定位问题: 搜集了一些python最重要的内建异常类名: AttributeError:属性错误, ...
- Python中常见的报错名称
Python中常见的报错名称 1.SyntaxError 语法错误.看看是否用Python关键字命名变量,有没有使用中文符号,运算符.逻辑运算符等符号是不是使用不规范. 2.IndentationEr ...
- Python中对时间日期的处理方法简单汇总
这篇文章主要介绍了Python实用日期时间处理方法汇总,本文讲解了获取当前datetime.获取当天date.获取明天/前N天.获取当天开始和结束时间(00:00:00 23:59:59).获取两个d ...
- 解决 python 中,时间日期不能序列化的问题
在python 中, 你在数据库娶到了数据中如果含有时间日期,那么你在向前端作为json对象传递的时候呢,就会报错.大致如下: TypeError: datetime.datetime(2017, 1 ...
- Python 中常见错误总结
IndentationError: unexpected indent Python 中强制缩进,, IndentationError: unexpected indent 缩进错误 这类错误非常常见 ...
随机推荐
- 如何使用 stl 进行排列组合?
#include <iostream> #include <vector> #include <algorithm> //从 indexs 集合中选择 num 个元 ...
- offset,scroll,client系列
offsetHeight: 元素高,height+border+paddingoffsetWidth: 元素宽,width+border+paddingoffsetTop: 距离offsetParen ...
- Red Gate系列 - SQL各种工具
Red Gate系列 - SQL各种工具 Red Gate系列文章: Red Gate系列之一 SQL Compare 10.4.8.87 Edition 数据库比较工具 完全破解+使用教程 Red ...
- idea java web 使用说明
String realPath = request.getSession().getServletContext().getRealPath(uploadPath);//上传压缩包所在目录 ...
- python之路:进击的小白
1.hello world print("hello world") 2.变量定义的规则 变量名只能是 字母.数字或下划线的任意组合 变量名的第一个字符不能是数字 以下关键字不能声 ...
- iOS git 托管代码 常用几个操作
学习 git 切换分支 1 从远程下载一个分支develop(本地没有的) (1) git fetch origin develop (2) git checkout develop (默认 分支切 ...
- linux切换用户命令
1. 切换用户的命令为:su +username 2.从普通用户切换到root用户:sudo su 3.退回到原来的用户:exit命令或logout,或者ctrl+d 4.如果要切换到新用户的工作环境 ...
- Linux安装jdk10
1.官网下载jdk10 下载方式两种,一种是wget下载,一种是windows系统下载,然后上传到linux系统上. 2.解压到/usr/local/java mkdir /usr/local/jav ...
- JSON.parse和JSON.stringify的作用
//JSON.parse将字符串格式json转化为json对象 var str='{"name":"lingling","age":&quo ...
- MySQL数据库基本操作(三)
MySQL补充: mysql是关系型数据库,关系数据库,是建立在关系模型基础上的数据库,现实世界中的各种实体,以及实体之间的各种联系,均用关系模型(table)来表示.#关系模型就是指二维表格模型,因 ...