dayjs字符串转时间戳

dayjs.extend(dayjs_plugin_utc)
dayjs.extend(dayjs_plugin_customParseFormat)
dayjs.locale(‘zh-cn’)

let t1 = 字符串转时间戳(‘1小时前’, true)

function 字符串转时间戳(str, 显示转换后格式时间) {
//dayjs.extend(dayjs_plugin_utc)
// dayjs.extend(dayjs_plugin_customParseFormat)
// dayjs.locale(‘zh-cn’)
//依赖 dayjs https://cdn.jsdelivr.net/npm/dayjs/dayjs.min.js
//https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.11/plugin/customParseFormat.min.js
logi(‘>>>字符串转时间’, str)
//dayjs(“12-25-1995”, “MM-DD-YYYY”)
let t1 = time();
if (/1{2}:[0-9]{2}KaTeX parse error: Expected '}', got 'EOF' at end of input: …-9]{2}:[0-9]{2}')
t1 = dayjs(str, “HH:mm”)

}
if (str.indexOf('昨天') > -1) {
    logi('昨天')
    str = str.replace('昨天', '')
    logi('昨天 ^[0-9]{2}:[0-9]{2}$')
    t1 = dayjs(str, "HH:mm")
    t1 = t1.subtract(1, 'day')

}
if (str.indexOf('上午') > -1) {
    logi('昨天')
    t1 = dayjs(str, "A hh:mm")

}
if (str.indexOf('下午') > -1) {
    logi('下午')
    t1 = dayjs(str, "A hh:mm")

}
if (str.indexOf('分钟前') > -1) {
    logi('分钟前')
    str = str.replace('分钟前', '').trim() - 0
    t1 = dayjs().subtract(str, 'm')

}
if (str.indexOf('小时前') > -1) {
    logi('分钟前')
    str = str.replace('小时前', '').trim() - 0
    t1 = dayjs().subtract(str, 'h')

}
if (显示转换后格式时间) {
    logi('转换后格式化时间:' + t1.format('YYYY-MM-DD HH:mm'))
}
return t1;

}


  1. 0-9 ↩︎

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值