码迷,mamicode.com
首页 > Web开发 > 详细

JS库

时间:2018-05-10 17:34:12      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:span   lis   bst   fun   UNC   his   form   time   for   

    
//毫秒转换成时间格式方法
function timestampToTime(timestamp) { var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 Y = date.getFullYear() + ‘-‘; M = (date.getMonth()+1 < 10 ? ‘0‘+(date.getMonth()+1) : date.getMonth()+1) + ‘-‘; D = date.getDate() + ‘ ‘; h = date.getHours() + ‘:‘; m = date.getMinutes() + ‘:‘; s = date.getSeconds(); return Y+M+D+h+m+s; }

 

        Date.prototype.Format = function (fmt) { 
            var o = {
                "M+": this.getMonth() + 1, //月份 
                "d+": this.getDate()-1, //
                "h+": this.getHours(), //小时 
                "m+": this.getMinutes(), //
                "s+": this.getSeconds(), //
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
                "S": this.getMilliseconds() //毫秒 
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }        
        var signTime = new Date().Format("yyyy年MM月dd日"); //时间格式的转换

 

var wm_txt1 = $("#salesNoId").val().trim(); //水印显示的内容    给表格添加水印

var canvas = document.createElement(‘canvas‘);
var ctx = canvas.getContext(‘2d‘);
ctx.fillStyle = ‘rgba(0,0,0,0.1)‘;
ctx.clearRect(0, 0, 100, 100);
ctx.font = ‘20px Arial‘;
ctx.translate(30, 100);
ctx.rotate(-45 * Math.PI / 180);
ctx.fillText(wm_txt1, 0, 18);
var imgdata = canvas.toDataURL();
var tbccChild = document.getElementById("index_table"); //表格的id
tbccChild.style.backgroundImage = ‘url(‘ + imgdata + ‘)‘;

 

//获取当前时间的前一天,后一天
let curDate = new Date(); 
let preDate = new Date(curDate.getTime() - 24*60*60*1000); 

 

JS库

标签:span   lis   bst   fun   UNC   his   form   time   for   

原文地址:https://www.cnblogs.com/panrui1994/p/9006619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!