strftime

odoo时间过滤

筅森魡賤 提交于 2020-02-15 23:51:34
Odoo中本日、本月、上月过滤器实现方法 Odoo中本日、本月、上月过滤器实现方法 <filter string="今日订单" name="today" invisible="0" domain="[('date','=', current_date)]"/> <filter string="本月订单" name="month" invisible="0" domain="[('date','>=', time.strftime('%Y-%m-01')),('date','<', (context_today() + relativedelta(months=1)).strftime('%Y-%m-01') ) ]"/> <filter string="上月订单" name="month2" invisible="0" domain="[('date','<', time.strftime('%Y-%m-01')),('date','>=', (context_today() - relativedelta(months=1)).strftime('%Y-%m-01') ) ]"/> <filter string="本年订单" name="year" invisible="0" domain="[('date','<=', time.strftime('%Y-12-31')),(

Awk基本入门[6] Additional Awk Commands 5

做~自己de王妃 提交于 2020-02-14 19:00:58
1、System Function You can use the system built-in function to execute system commands. Please note that there is a difference between two way communication and system command. In "|&", you can pass the output of any awk command as input to an external command, and you can receive the output from the external command in your awk program (basically it is two way communication). Using the system command, you can pass any string as a parameter, which will get executed exactly as given in the OS command line, and the output will be returned (which is not same as the two way communication). The

时间处理模块time

邮差的信 提交于 2020-02-12 23:37:25
一、时间概念 1.1 时间戳     时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总   秒数。通俗的讲, 时间戳是一份能够表示一份数据在一个特定时间点已经存在的完整的可验证的数据。 1.2 时区   为了时间各国的时间能统一,使用了时区的概念。以格林尼治为0时区,总24个时区。 东+,西- 1.3 夏令时   为了节约夏天的能源,开发出来的一个调节时间。 然后实际证明没什么软用。 中国以前也用过,但是取消掉了。 二、python代码中的时间   时间有三种格式:       时间戳(timestamp)       时间字符串(Format String)       结构化的时间(struct_time):(year=2018, month=5, day=1, hour=16, min=37, sec=6)   python中的时间模块       time       datetime       python-dateutil (pip install)   2.1 time 模块   常用方法:     time.time()   当前的时间戳     time.sleep()   停止多少时间 2.1.1 时间戳 与 结构化时间 之间相互转换 import time print(time

python3日期格式化操作

你说的曾经没有我的故事 提交于 2020-02-07 21:29:26
python中可以用来格式化日期的模块可以是time或者datetime,如果要进行时间偏移的话,可以使用datetime模块。 time模块: time.strptime(str, format)将字符串转为 struct_time 对象。 time.strftime(format, t),将 struct_time对象 转为字符串。 t1 = '2020-02-05T16:00:00.000+0000' t = time.strptime(t1, '%Y-%m-%dT%H:%M:%S.%f+0000') t2 = time.strftime('%Y-%m-%d %H:%M:%S', t) print(t2) # 2020-02-05 16:00:00 datetime模块: datetime.strptime(str, format)将字符串转为格林威治GMT/UTC时间,它是datetime对象。 datetime对象.strftime(format)可以得到符合日期格式的字符串。 t1 = '2020-02-05T16:00:00.000+0000' t = datetime.strptime(t1, '%Y-%m-%dT%H:%M:%S.%f+0000') t = t + timedelta(hours=8) t2 = t.strftime('%Y-%m-%d %H:%M

python datetime模块杂记

心已入冬 提交于 2020-02-02 19:37:43
开发过程中经常会遇到时间、日期方面的处理,今天mark下python datetime模块用法。 一、python 日期时间格式化符号 格式化符号 含义 %y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数(0-23) %I 12小时制小时数(01-12) %M 分钟数(00=59) %S 秒(00-59) %a 本地简化星期名称 %A 本地完整星期名称 %b 本地简化的月份名称 %B 本地完整的月份名称 %c 本地相应的日期表示和时间表示 %j 年内的一天(001-366) %p 本地A.M.或P.M.的等价符 %U 一年中的星期数(00-53)星期天为星期的开始 %w 星期(0-6),星期天为星期的开始 %W 一年中的星期数(00-53)星期一为星期的开始 %x 本地相应的日期表示 %X 本地相应的时间表示 %Z 当前时区的名称 %% %号本身 二、datetime模块内容 datetime模块所含类如下表: 类 功能 date 日期对象,常用的属性有year, month, day time 时间对象 datetime 日期时间对象,常用的属性有hour, minute, second, microsecond datetime_CAPI 日期时间对象C语言接口

Need small help in converting date format in ruby

荒凉一梦 提交于 2020-02-02 06:24:04
问题 Here are some outputs: Date.today => Mon, 25 Jun 2012 Date.today.to_formatted_s(:long_ordinal) => "June 25th, 2012" Date.today.strftime('%A %d, %B') => "Monday 25, June" Now I need output in the format ie: Monday 25th, June or Thrusday, 1st, October Problem is to_formatted_s and strftime apply only on date and both or them return string. How can I get the output in the way I need. 回答1: You can use Date::DATE_FORMATS to add a new customized format, and Integer.ordinalize to get the day ordinal

Need small help in converting date format in ruby

橙三吉。 提交于 2020-02-02 06:22:31
问题 Here are some outputs: Date.today => Mon, 25 Jun 2012 Date.today.to_formatted_s(:long_ordinal) => "June 25th, 2012" Date.today.strftime('%A %d, %B') => "Monday 25, June" Now I need output in the format ie: Monday 25th, June or Thrusday, 1st, October Problem is to_formatted_s and strftime apply only on date and both or them return string. How can I get the output in the way I need. 回答1: You can use Date::DATE_FORMATS to add a new customized format, and Integer.ordinalize to get the day ordinal

Python与日期、时间相关的内置模块:time、datetime、calendar,以及第三方模块:moment(使用体验更好)

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-31 22:56:54
Python 与日期、时间相关的内置模块,主要有: time 、 datetime 、 calendar 等,一般常见的问题,使用它们就足够了,但遇到复杂度很高的需求时,代码的可读性就会变得很差,所以,我们还可以使用体验更好的第三方模块: moment 。本文会从内置模块介绍到第三方模块。 time time 是用来表示时分秒。 获取时间 import time print ( time . time ( ) ) 1559201353.5570097 得到的是一个 时间戳 ,是从 1970-01-01 00:00:00 (时间基准点)到现在的秒数,数据类型是浮点型,是 UTC 时间。 UTC 的由来,全球分为24个时区,每个时区都自己的本地时间,为了能有一个统一的时间,所以设置了 UTC(Universal Time Coordinated,通用协调时),都与英国伦敦的本地时间一样。 但时间戳对于人来讲,可读性极差,所以我们需要将其转换成日常使用的形式。 转换时间戳 import time # 输出 UTC 时间的年月日时分秒结构体 print ( 'UTC:' , time . gmtime ( time . time ( ) ) # 输出本地时间的年月日时分秒结构体 print ( 'localtime:' , time . localtime ( time . time (

python实现自动监控网站并发送邮件告警

独自空忆成欢 提交于 2020-01-31 10:53:51
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://mapengfei.blog.51cto.com/1552412/1841731 通过定时执行python脚本,可以实现定期批量访问网站,如果发现网站打不开,第一时间发邮件到管理员邮箱进行预警 这里用的是python3.5 需要安装的插件: smtplib:发邮件需要用到 pycurl:访问网站时会需要用到 linecache:在读取txt网站清单时需要用到 具体思路: python程序从txt里面批量读取到网站的信息,通过Curl.py模拟浏览器去访问网站,并且把访问的结果写入到以自己的网站名称-日期.txt格式的文件中记录;有几种情况: 1、如果发现打不开了,直接发邮件提示网站已经打不开 2、发现可以打开,读取文件中上一次访问的情况(读取txt文件最后一行), 1)如果发现上一次是打不开的,发邮件提醒网站已经恢复了 2)如果发现上一次是打得开的(200的返回码),只是记录网站访问的日志就可以了 总共4个文件, Email.py是邮件类,主要用来发邮件的时候调用,这里需要按照你的情况改成你的邮箱(msg['From']),邮箱服务器地址(SMTP地址),和你的邮箱密码(SMTP.login) Email.py #!/usr/bin/python #-*-

python 之时间模块 time

六眼飞鱼酱① 提交于 2020-01-27 08:23:37
time模块可以用于格式化日期和时间 ,时间间隔是以秒为单位的浮点小数。每个时间戳都以自从1970年1月1日午夜(历元)经过了多长时间来表示。 下面是time模块常用的一些时间格式转换的函数。时间戳可以直接比较大小。 1 import time 2 3 #想时间戳和格式化好的时间互相转换的话,都要先转成时间元组,然后才能转 4 print(int(time.time())) #当前时间戳 5 cur_time = time.strftime('%Y-%m-%d %H:%M:%S') 6 cur_time = time.strftime('%H%M%S') #取当前时间的格式化时间 7 cur_time1 = time.strftime('%Y-%m-%d') 8 print(cur_time1) 9 10 print(type(cur_time1)) 11 print(time.gmtime())#默认取标准时区的时间元组,如果传入了一个时间戳,那么就把这个时间戳转换成时间元组。 12 print(time.timezone) #和标准时间相差了几个小时 13 print(time.gmtime(1516005840)) #标准时区。 14 cur_time= time.localtime(1516005840) #默认取当前时区的时间元组,如果传入了一个时间戳