首页笔记趣玩其他
JavaScriptTypeScriptReactNpmGitCss小程序面试题
章节
AllStringArrayObjectRegExpDate
    Date
    日期中获取时分秒
    const time = new Date(2024, 2, 7, 11, 7, 0); const timeFromDate = date => date.toTimeString().slice(
    lhh|07/31/2024 14:13
    Date
    找出日期是当年中的第几天
    const dayOfYear = (date) => Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60
    lhh|07/31/2024 14:13
    Date
    计算两个日期间的天数
    const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000) d
    lhh|07/31/2024 14:13
    Date
    当天0点
    new Date(new Date().setHours(0, 0, 0, 0)) new Date(new Date().toLocaleDateString().replace(/-/g, '/'
    lhh|07/31/2024 14:13
    Date
    处理时间字符串
    // toLocaleDateString() // 获取当前日期,苹果和安卓获取的字符串不同 2021/12/10 // toLocaleTimeString(); // 获取当前时间 下午5
    lhh|07/31/2024 14:13
    RegExp
    去除空格并将其后的第一个字母大写
    function capitalizeAfterSpace(str) { return str .replace(/^\s+|\s+(?=\s)/g, "") .replace(/
    lhh|07/31/2024 14:12
    RegExp
    提取括号中的内容
    const str = "123[abc]456{zzz}789[def]10"; // 包括括号 const reg1 = /\[(.+?)\]/g; // [] 中括号 console.log(
    lhh|07/31/2024 14:11
    RegExp
    以最外层括号截取内容
    const str = "这里是内容(括号中的内容(haha),123)"; str.split(new RegExp("\\((.*)\\)")); // ["这里是内容", "括号中的内容(hah
    lhh|07/31/2024 14:11
    RegExp
    匹配字符串中长度大于 2 的公共元素子串
    const s = "021Abc99Abc9"; if (/(.{3,}).*\1/g.test(s)) { console.log(true); }
    lhh|07/31/2024 14:11
    RegExp
    匹配 - 和小写字符
    let s = "get-ele-by"; s.replace(/-\w/g, (w) => w.slice(1).toUpperCase()); // 'getEleBy'
    lhh|07/31/2024 14:11