常用模块之

1import datetime 2import time 3 4print(time.strftime('%y/%m/%d %X')) 5 输出结果:18/06/05 20:40:46 6 7 8print(time.strftime('%Y/%m/%d %X')) 9 输出结果:2018/06/05 20:43:20 10 11注意:区分大小写带来结果的不同 12 13print(time.localtime()) 14 15输出结果: 16time.struct_time(tm_year=2018, tm_mon=6, tm_mday=5, tm_hour=20, tm_min=46, tm_sec=9, tm_wday=1, tm_yday=156, tm_isdst=0)注意输出结果是一个元组,所以我们可以通过索引取我们需要的特定值

注意:计算机认识的时间只能是'时间戳'格式

1import datetime 2 3# print(datetime.datetime.now()) #返回 2016-08-19 12:47:03.941925 4#print(datetime.date.fromtimestamp(time.time()) ) # 时间戳直接转成日期格式 2016-08-19 5# print(datetime.datetime.now() ) 6# print(datetime.datetime.now() + datetime.timedelta(3)) #当前时间+37# print(datetime.datetime.now() + datetime.timedelta(-3)) #当前时间-38# print(datetime.datetime.now() + datetime.timedelta(hours=3)) #当前时间+3小时 9# print(datetime.datetime.now() + datetime.timedelta(minutes=30)) #当前时间+3010 11 12# 13# c_time = datetime.datetime.now() 14# print(c_time.replace(minute=3,hour=2)) #时间替换输出结果:

  2018-06-05 21:30:59.150399
  2018-06-05 02:03:59.150399

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

PHP获取某年某月开始和结束的时间戳

/月份开始结束时间戳$y年$m月/functionmFristAndLast($y"",$m"")if($y"")$ydate("Y");if($m"")$mdate("m");$msprintf("%02d",intval($m));$ystrpad(intva

Linux总结笔记1

1.常用系统工作命令1echo命令用于在终端显示字符串或输出变量提取后的值,格式为:“echo字符串|$变量”。2date命令用于显示及设置系统的时间或日期,格式为:"date选项指定的格式"。3例如:date"%Y%m%d%H:%M:%S"4reboot

mysql简单常用语句汇总

1\.常用函数uuid和时间戳SELECTUUID(),UNIX_TIMESTAMP();将时间戳转为日期格式FROM_UNIXTIME(mw.created_at,'%Y%m%d%H:%i:%s')设置参数select@m_no:max(m_no)fromvc_m;set@m

mysql相似于oracle的to_char() to_date()方法

mysql日期和字符相互转换方法date\_format(date,'%Y%m%d')  oracle中的to\_char();str\_to\_date(date,'%Y%m%d')  oracle中的to\_date();%Y:代表4位的年份%y:代表2为的年份

mysql timestamp

 select from\_unixtime(m.createdAt, '%Y%m%d %H:%i:%s') from kfrobotaidlog m;select m.customeruid, from\_unixtime(m.createtime, '%Y%m%d %H:%i:%s') as \datetime\, m.kfui