1、导入time模块   import time

2、获取当前时间的时间戳   time.time()

3、获取当前格式化好的时间   time.strftime(想要获取的格式)

4、时间戳和格式化好的时间互相转化(都要先转换成时间元祖)

4.1、时间戳转化成格式化好的时间(先转换成时间元祖)

步骤:时间元祖=time.gmtime(时间戳)——转化后格式化的时间=time.strftime('%Y-%m-%d %h:%m:%s',时间元祖)

gmtime获取的是标准时区时间,localtime获取的当地时间,当地时间比标准时间快了8小时

4.2格式化好的时间转化成时间戳(也要先转换时间元祖)

步骤:时间元祖=time.strptime('2019-05-07 16:29:00','%Y-%m-%d %H:%M:%S')——转化后的时间戳=time.mktime(时间元祖)

小题:

1、 格式化好的时间转时间戳,如果不传的话,就直接获取当前时间戳

注意:格式化好的时间转时间戳的函数中,传入的格式化好的时间,必须按照你format=的格式去传,否则会报错

2、时间戳转化成格式化好的时间,如果没有传时间戳,就直接获取当前的格式化时间

												

time模块:时间戳和格式化好的时间表示方法及互相转换方法的更多相关文章

  1. JavaScript时间戳与其格式化

    在 PHP + MySQL (日期类型为datetime) + ajax 应用中,有时候需要用 JavaScript 将时间戳类型格式化为一般的时间类型格式.下面提供一些转换的方法,比较常见的一些总结 ...

  2. PHP date 格式化一个本地时间/日期

    PHP date 格式化一个本地时间/日期 date (PHP 4, PHP 5) date — 格式化一个本地时间/日期 说明 string date ( string $format [, int ...

  3. Objective-C时间戳转换的转换和时间

    什么是时间戳? 时间戳(timestamp),一般是一个字符序列.唯一地标识某一刻的时间.数字时间戳技术是数字签名技术一种变种的应用. 思考:简单来讲就是依据文件hash加密后生成的摘要和时间生成的时 ...

  4. JS格式化日期时间的方法

    //格式化时间的方法 function format(fmt, date) { var o = { "M+": date.getMonth() + 1, //月份 "d+ ...

  5. Java 格式化日期、时间

    有三种方法可以格式化日期.时间. 1.使用DateFormat类 获取DateFormat实例: DateFormat.getDateInstance()    只能格式化日期      2019年5 ...

  6. python中的时间戳和格式化之间的转换

    import time #把格式化时间转换成时间戳 def str_to_timestamp(str_time=None, format='%Y-%m-%d %H:%M:%S'): if str_ti ...

  7. ⑤JS返回格式化的当前时间和上周时间

    首先对时间进行格式化 返回上周时间和当前时间

  8. JSP页面格式化数字或时间 基于jstl的

    jsp页面格式化数字或时间 转载自: http://blog.csdn.net/hakunamatata2008/archive/2011/01/21/6156203.aspx Tags fmt:re ...

  9. js格式化时间的方法

    方法一:用js格式化时间的方法. Date.prototype.format =function(format) { var o = { "M+" : this.getMonth( ...

随机推荐

  1. 精讲RestTemplate第10篇-使用代理作为跳板发送请求

    本文是精讲RestTemplate第10篇,前篇的blog访问地址如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层 ...

  2. Url跳转漏洞常见

    Url跳转漏洞常见出现点: 1.用户登录.统一身份认证处,认证完后会跳转. 2.用户分享.收藏内容过后,会跳转. 3.跨站点认证.授权后,会跳转. 4.站内点击其它网址链接时,会跳转. Url跳转漏洞 ...

  3. python基础 Day9

    python Day9 函数的初识 #代码的可读性较好 s=[1,2,3,4,5,5] def list_len(S): count=0 for i in s: count+=1 print(coun ...

  4. AOP计算方法执行时长

    AOP计算方法执行时长 依赖引入 <dependency> <groupId>org.springframework.boot</groupId> <arti ...

  5. 构造vlan报文

    #!/usr/bin/python from scapy.all import * packet = Ether(src='dc:99:14:01:a3:5e', dst='ff:ff:ff:ff:f ...

  6. nova 通过 python curl 创建虚拟机---keystone v2

    #! /bin/python #coding=utf- import urllib2 import json import requests # token post_url = 'http://12 ...

  7. SpringBoot集成Swagger2,3分钟轻松入手!

    一.引入maven <dependency> <groupId>io.springfox</groupId> <artifactId>springfox ...

  8. A review of learning in biologically plausible spiking neural networks

    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! Contents: ABSTRACT 1. Introduction 2. Biological background 2.1. Spik ...

  9. Java多线程_JUC包下的阻塞队列

    在前面我们提到了阻塞队列,也用过了LinkedBolckingQueue队列了,在这里,我们主要对 ArrayBlockingQueue,PriorityBlockingQueue,DelayQueu ...

  10. PAT甲级真题 A1025 PAT Ranking

    题目概述:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...