• python 对时间操作


    from datetime import datetime,timedelta

    'date_test':fields.function(_datetime_all,type='datetime',  string=u'测试'),
    函数:形式
    def _datetime_all(self, cr, uid, ids, field_name, arg, context=None):

            res = {}
            for order in self.browse(cr, uid, ids, context=context):
                aa = order.lreport_date
                dt = datetime.strptime(aa, "%Y-%m-%d %H:%M:%S")
                d = dt-timedelta(hours=8)
                order.date_test=d
                va= order.date_test
                res[order.id] = va

            return  res



    这个是on_change事件:
    def on_change_time(self,cr,uid,ids,date,context=None):
            result={}
            if date:
                dt = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
                d = dt-timedelta(hours=8)
                result['date_test']=d
            return {'value':result}


     <field name="lreport_date"  on_change="on_change_time(lreport_date)"/>
     on_change="on_change_time(date)"

    <script type="text/javascript">
        //替换字符串  
        function Replace(str, from, to) {
            return str.split(from).join(to);
        }
        // 日期类型格式成指定的字符串
        function FormatDate(date, format) {
            format = Replace(format, "yyyy", date.getFullYear());
            format = Replace(format, "MM", GetFullMonth(date));
            format = Replace(format, "dd", GetFullDate(date));
            format = Replace(format, "HH", GetFullHour(date));
            return format;
        }
        //js日期字符串转换成日期类型
        function parseDate(dateStr) {
            return new Date(Replace(dateStr, "-", "/"));
        }
        //增加月  
        function AddMonths(date, value) {
            date.setMonth(date.getMonth() + value);
            return date;
        }
        //增加天  
        function AddDays(date, value) {
            date.setDate(date.getDate() + value);
            return date;
        }
        //增加时
        function AddHours(date, value) {
            date.setHours(date.getHours() + value);
            return date;
        }
        //返回月份(两位数)  
        function GetFullMonth(date) {
            var v = date.getMonth() + 1;
            if (v > 9) return v.toString();
            return "0" + v;
        }
     
        //返回日(两位数)  
        function GetFullDate(date) {
            var v = date.getDate();
            if (v > 9) return v.toString();
            return "0" + v;
        }
        //返回时(两位数)
        function GetFullHour(date) {
            var v = date.getHours();
            if (v > 9) return v.toString();
            return "0" + v;
        }
        //比较两个时间
        function compareDate() {
            var mydate = AddDays(parseDate("2012-08-23"), 1);
            var nowdate = new Date();
            if (nowdate.getTime() < mydate.getTime()) {
                return FormatDate(nowdate, "yyyy-MM-dd");
            }
            return FormatDate(mydate, "yyyy-MM-dd");
        }
    </script>

  • 相关阅读:
    php一些实用的自制方法
    php商城数据库的设计 之无限分类
    thinkphp的where 之 or的使用
    thinkphp 接收文件并处理
    thinkphp验证器
    Html中文字过多,单行超出和多行超出显示省略号
    THINKPHP 模板上传图片--后台接收图片
    UIStackView,真正的自动布局
    iOS 为什么有的APP,没有在Devices显示出来?
    访问iOS APP的8080端口服务
  • 原文地址:https://www.cnblogs.com/1314520xh/p/7920176.html
Copyright © 2020-2023  润新知