---
title: "python 时间的概念要点"
author: "lionbule"
date: "2012-11-20T13:34:31Z"
tags: ["Python", "time"]
categories: ["编程语言"]
slug: "python"
draft: false
lastmod: "2012-11-20T13:35:48Z"
id: 1730550
url: "https://lionbule.iteye.com/blog/1730550"
---

1、在Python中，通常有这几种方式来表示时间：时间戳 、格式化的时间字符串 、元组（struct\_time共九个元素）。由于Python的time模块实现主要调用C库，所以各个平台可能有所不同。

 

2、UTC（Coordinated Universal Time，世界协调时）亦即格林威治天文时间，世界标准时间。在中国为UTC+8。DST（Daylight Saving Time）即夏令时。

 

3、时间戳（timestamp）的方式：通常来说，**时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量**。我们运行“type(time.time())”，返回的是float类型。返回时间戳方式的函数主要有time()，clock()等。

 

4、元组（struct\_time）方式：struct\_time元组共有9个元素，返回struct\_time的函数主要有gmtime()，localtime()，strptime()。下面列出这种方式元组中的几个元素：

 

![](http://dl.iteye.com/upload/picture/pic/120312/afdbf5fc-eb1d-33e6-bc3f-a8d3b1c339ac.jpg)

 

[http://qinxuye.me/article/details-about-time-module-in-python/](http://qinxuye.me/article/details-about-time-module-in-python/)