亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

js 轉換時間戳的寫法Script

標簽:
JavaScript

摘要:自带方法vartime=newDate(毫秒)函数加正则functiongetLocalTime(nS){returnnewDate(parseInt(nS)*1000).toLocaleString().replace(/:/d{1,2}$/,'');}alert(getLocalTime(1293072805));3.自定义时间格式的方法(可自定义时间格式)functionchangeDateFormat(cellval){if(cellval!=null){vardat

var time= new Date(毫秒)function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:/d{1,2}$/,' '); } alert(getLocalTime(1293072805));

3.自定义时间格式的方法(可自定义时间格式)

function changeDateFormat(cellval) { if (cellval != null) { var date = new Date(cellval); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var Hour = date.getHours(); var Min = date.getMinutes(); var Sen = date.getSeconds(); return date.getFullYear() + "-" + month + "-" + currentDate + " " + getCorr(Hour) + ":" + getCorr(Min) + ":" + getCorr(Sen); }}function getCorr(num) { if (parseInt(num) < 10) { num = '0' + num; } return num;}

4.大神写法(高度自定义)

// 转换时间戳 var format = function (time, format) { var t = new Date(毫秒); var tf = function (i) { return (i < 10 ? '0' : '') + i }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) { switch (a) { case 'yyyy': return tf(t.getFullYear()); break; case 'MM': return tf(t.getMonth() + 1); break; case 'mm': return tf(t.getMinutes()); break; case 'dd': return tf(t.getDate()); break; case 'HH': return tf(t.getHours()); break; case 'ss': return tf(t.getSeconds()); break; } }) } $("#statrtime").val(format(new Date().getTime(), 'yyyy/MM/dd HH:mm:ss'));

    1. 函数加正则

    1. 自带方法

  • 以上是
  • js 转换时间戳的写法Script
  • 的内容,更多 
  • 写法 转换 时间 js 
  • 的内容,请您使用右上方搜索功能获取相关信息。
  • 原文链接:https://www.aliyun.com/jiaocheng/975822.html?spm=5176.100033.9.5.LP0zJ2

    點擊查看更多內容
    TA 點贊

    若覺得本文不錯,就分享一下吧!

    評論

    作者其他優質文章

    正在加載中
    • 推薦
    • 評論
    • 收藏
    • 共同學習,寫下你的評論
    感謝您的支持,我會繼續努力的~
    掃碼打賞,你說多少就多少
    贊賞金額會直接到老師賬戶
    支付方式
    打開微信掃一掃,即可進行掃碼打賞哦
    今天注冊有機會得

    100積分直接送

    付費專欄免費學

    大額優惠券免費領

    立即參與 放棄機會
    微信客服

    購課補貼
    聯系客服咨詢優惠詳情

    幫助反饋 APP下載

    慕課網APP
    您的移動學習伙伴

    公眾號

    掃描二維碼
    關注慕課網微信公眾號

    舉報

    0/150
    提交
    取消