import time
时间相关的操作,时间有三种表示方式:
- 时间戳 1970年1月1日之后的秒,即:time.time()
- 格式化的字符串 2014-11-11 11:11, 即:time.strftime('%Y-%m-%d')
- 结构化时间 元组包含了:年、日、星期等... time.struct_time 即:time.localtime()
print time.time()
print time.mktime(time.localtime())
print time.gmtime() #可加时间戳参数
print time.localtime() #可加时间戳参数
print time.strptime('2014-11-11', '%Y-%m-%d')
print time.strftime('%Y-%m-%d') #默认当前时间
print time.strftime('%Y-%m-%d',time.localtime()) #默认当前时间
print time.asctime()
print time.asctime(time.localtime())
print time.ctime(time.time())
import datetime
'''
datetime.date:表示日期的类。常用的属性有year, month, day
datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond
datetime.datetime:表示日期时间
datetime.timedelta:表示时间间隔,即两个时间点之间的长度
timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
strftime("%Y-%m-%d")
'''
import datetime
print datetime.datetime.now()
print datetime.datetime.now() - datetime.timedelta(days=5)
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
格式化占位符

import time的更多相关文章
- ES6模块import细节
写在前面,目前浏览器对ES6的import支持还不是很好,需要用bable转译. ES6引入外部模块分两种情况: 1.导入外部的变量或函数等: import {firstName, lastName, ...
- spring源码分析之@ImportSelector、@Import、ImportResource工作原理分析
1. @importSelector定义: /** * Interface to be implemented by types that determine which @{@link Config ...
- Python标准模块--import
1 模块简介 作为一个Python初学者,你首先要学会的知识就是如何引入其它模块或者包.但是,我发现有些开发者虽然使用Python很多年,依然不了解Python引入机制的灵活性.这篇文章,我们就会研究 ...
- css和@import区别用法
css和@import都是调用外部样式表的方法. 一.用法 (1)link: <link rel="stylesheet" type="text/css" ...
- 从爬取湖北某高校hub教务系统课表浅谈Java信息抓取的实现 —— import java.*;
原创文章与源码,如果转载请注明来源. 开发环境:Myeclipse,依赖包:apache-httpclient . Jsoup.base64 一.概述 整个系统用Java开发.我们现在要做的是类似于超 ...
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- python学习笔记-import utils报错
今天遇到一个坑爹的问题,查找了半天原因,终于解决了,在此特地记录一下. 运行环境:Windows eclipse 我在eclipse中配置了python的运行环境,在eclipse中编写python代 ...
- ImportError: cannot import name '_imagingtk'
问题描述 使用tkinter画pillow生成的图片时,在tkinter中抛出此异常. 解决方案 pip install -I --no-cache-dir Pillow 更新pillow 重启解决一 ...
- import renumber.py in pymol
cp renumber.py /usr/local/lib/python2.7/dist-packages/pymol import renumber or run /path/to/renumber ...
- python import, from xx import yy
区别: 用import modulexx/packagexx.moduleyy是导入某一模块,如果想引用模块的内容(class, method,variables...)必须用全名,即 [module ...
随机推荐
- 本地磁盘文件夹共享到虚拟机上的linux系统中
1. 将本地的一个文件夹设置为共享文件 2.点击 虚拟机菜单中的 虚拟机->设置->选项->共享文件夹->总是启用->添加(将上一步骤设置的共享文件夹添加到里面) 3. ...
- 批处理BAT(一)
批处理 全盘根目录下查找文件夹并删除(1)@echo offfor %%a in (C D E F G H) DO (cd\if exist "%%a:\123\" rd /s / ...
- 重写ddt的mk_test_name方法
一. 测试用例名字的问题 使用ddt做测试,得到的测试报告中,测试用例的名字默认以_01, _02, _03...递增的形式结尾,这时我希望用例名能够以_api_name结尾,比如注册模块,希望看到的 ...
- Office 2016 (Preview)
Office 2016 Preview for MAC (预览版) https://products.office.com/zh-CN/mac/mac-preview 安装下载:http://go.m ...
- 51nod 1102 单调栈
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 1102 面积最大的矩形 基准时间限制:1 秒 空间限制:1310 ...
- LeetCode OJ:Minimum Path Sum(最小路径和)
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- XSLT 教程
应用自http://www.w3school.com.cn/xsl/index.asp XSL 指扩展样式表语言(EXtensible Stylesheet Language). 万维网联盟开始发展 ...
- L115
The reasons of reading books - part I1. You will optimize your brain powerThis shouldn't come as a s ...
- SQLAlchemyの增删改查
用a*my写原味sql from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, I ...
- 【SQL查询】查询的值为空时,给出默认值_NVL函数
格式为: NVL( string1, replace_with) 功能:如果string1为NULL,则NVL函数返回replace_with的值,否则返回string1的值. 引申一下,此NVL的作 ...