时间戳、格式化时间相互转换的函数封装

import time
# =====封装函数:格式化时间转成时间戳======def format_time_to_timestamp(format_time=None):    if format_time:        time_tuple = time.strptime(format_time,‘%Y-%m-%d %X‘)        result = time.mktime(time_tuple)        return int(result)    return int(time.time())

#查看调用结果print(format_time_to_timestamp())print(format_time_to_timestamp(‘2009-10-10 18:01:11‘))

# ==========封装函数:时间戳转换成格式化时间==========def timestamp_to_format_time(timestamp=None,format=‘%Y-%m-%d %X‘):    if timestamp:        time_tuple = time.localtime(timestamp)        result = time.strftime(format,time_tuple)        return result    else:        return time.strftime(format)

#查看调用结果print(timestamp_to_format_time())print(timestamp_to_format_time(1255168871))

原文地址:https://www.cnblogs.com/xuexizongjie/p/10800359.html

时间: 2024-08-07 07:53:11

时间戳、格式化时间相互转换的函数封装的相关文章

时间戳与时间相互转换(13位)(转)

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. 1 /// 获取时间戳 2 /// </summary> 3 /// <returns></returns> 4 public static string GetTimeStamp(System.DateTime time) 5 { 6 long ts = ConvertDateTimeToInt(time); 7 return ts.T

SQL Server 格式化时间 之 format函数

select format(getdate(),'yyyy-MM-dd HH:mm:ss'); 要注意 yyyy-MM-dd这里MM是大写的, HH:mm:ss这里HH是大写的,mm是小写的,大小写意思不一样 更多详细查看https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

OC中关于时间的几个函数及格式化时间

// // main.m // 时间格式化 // // Created by Macro on 14-12-10. // Copyright (c) 2014年 Macro. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { //返回当前时间,以GMT为准 NSDate * date = [NSDate da

js 格式化时间日期函数小结

下面是脚本之家为大家整理的一些格式化时间日期的函数代码,需要的朋友可以参考下. 代码如下: Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(

python_时间戳和格式化时间转换封装函数

1.时间戳转换格式化时间 import time def timestamp_to_str(timestamp=None,format='%Y-%m-%d %H:%M:%S'): '''这个是把时间戳转换成格式化好的实际,如果不传时间戳,那么就返回当前的时间''' if timestamp: return time.strftime(format,time.localtime(timestamp)) else: return time.strftime(format,time.localtime

javascript中常见的函数封装 :判断是否是手机,判断是否是微信,获取url地址?后面的具体参数值,毫秒格式化时间,手机端px、rem尺寸转换等

// 判断是否是手机function plat_is_mobile(){ var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match

js时间格式化工具,时间戳格式化,字符串转时间戳

在开发中经常会用到时间格式化,有时候在网上搜索一大堆但不是自己想要的,自己总结一下,写一个时间格式化工具方便以后直接使用,欢迎大家来吐槽-- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

js时间戳格式化函数

/** * 格式化日期函数 * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 * (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 */Date.prototype.format = function(format){ var o = { "M+" : this.

格式化时间 与 时间戳的转换

2015-08-06 19:37:58 1 /*! 2 * <格式化时间与时间戳的转换> 3 * 4 * 2015/08/06 by <felove> 5 */ 6 #include <stdio.h> 7 #include <windows.h> 8 #include <time.h> 9 10 void timestampToFormat(time_t& t_1, tm& tm_1); 11 time_t formatToTi