import time

# 时间戳: 从1970-01-01 00:00:00开始计算. 未来存储的时候用是时间戳
print(time.time())
# 格式化时间
print(time.strftime("%Y-%m-%d %H:%M:%S")) # 用来显示的 # 2018-01-02 12:38:56
print(time.strftime("%Y-%m-%d %H:%M:%S %Z")) # ?D1¨²¡À¨º¡Á?¨º¡À?? # 结构化时间(python的时间)
print(time.localtime())
t = time.localtime()
print(t.tm_year)
print(t.tm_mon)
print(t.tm_min) # 重点:
# # 数据库里存储一个数字. 把它还原成我们的格式化时间
a = 0
# 先把这个时间戳转化成python中的结构化时间
t = time.localtime(a) # 本地化的东八区的时间
t = time.gmtime(a) # 格林尼治时间
# # 把一个结构化时间转化成格式化时间
s = time.strftime("%Y-%m-%d %H:%M:%S", t)
print(s) # 让用输入一个时间. 把这个时间转化成时间戳
user_input = input("请输入一个时间:")
# 把用户输入的字符串转化成结构化时间
struct_time = time.strptime(user_input, "%Y-%m-%d %H:%M:%S") # p: parse
# 转化成时间戳
num = time.mktime(struct_time)
print(num)

  

Python 时间的更多相关文章

  1. 浅谈Python时间模块

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

  2. python时间处理之datetime

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

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

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

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

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

  5. Python 时间日历类型

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

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

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

  7. [python] 时间序列分析之ARIMA

    1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量  进行观察测量,将在一系列时刻  所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...

  8. python—时间与时间戳之间的转换

    python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...

  9. python时间格式化

    import timeprint time.time()输出的结果是:1279578704.6725271 但是这样是一连串的数字不是我们想要的结果,我们可以利用time模块的格式化时间的方法来处理: ...

  10. Python时间处理之time模块

    1.time模块简介 time模块提供各种操作时间的函数  说明:一般有两种表示时间的方式:       第一种是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一 ...

随机推荐

  1. php curl 并发

    1.比较普通的curl 请求 $ch = curl_init();//初始化curl curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页 curl_seto ...

  2. hdu-3671-tarjin/割点方案

    http://acm.hdu.edu.cn/showproblem.php?pid=3671 给出一幅无向图,询问有多少种移除点对的方案使得剩下的连通分量个数大于1. 和上一题差不多的思路直接做n次t ...

  3. 2017-4-20/Redis的数据结构及应用场景

    1. 谈谈你对redis的理解,它的应用场景. Redis是一个key-value存储系统,它支持存储的value类型包括string字符串.list链表.set集合.sorted Set有序集合和h ...

  4. 在Eclipse上安装Activiti插件

    然后点击: Help ---> Install new SoftWare 然后在点击Add添加新的: 我们在Name上 写上 Activiti BPMN 2.0 designer Locatio ...

  5. suffix array后缀数组

    倍增算法 基本定义子串:字符串 S 的子串 r[i..j],i≤j,表示 r 串中从 i 到 j 这一段也就是顺次排列 r[i],r[i+1],...,r[j]形成的字符串. 后缀:后缀是指从某个位置 ...

  6. stund客户端使用结果说明

    stun服务器是用于检测网络类型的重要工具. 源码地址:https://svwh.dl.sourceforge.net/project/stun/stun/0.97/stund-0.97.tgz 或者 ...

  7. MyBatis Spring整合配置映射接口类与映射xml文件

    本文转自http://blog.csdn.net/zht666/article/details/38706083 Spring整合MyBatis使用到了mybatis-spring,在配置mybati ...

  8. 如何让一个div水平和垂直居中对齐

    以下方法来自百度知道:https://zhidao.baidu.com/question/558984366971173044.html 方法1: .parent { width: 800px; he ...

  9. jsp 中文乱码

    解决jsp中文乱码问题的几个步骤 1 jsp页面设置        <%@ page language="java" contentType="text/html; ...

  10. linux nginx 安装防火墙ngx_lua_waf

    ngx_lua_waf是一款开源的 基于 ngx_lua的 web应用防火墙 github地址是  https://github.com/loveshell/ngx_lua_waf 安装流程如下 1 ...