其他分享
首页 > 其他分享> > dayjs 获取距当前时间的相对时间字符串

dayjs 获取距当前时间的相对时间字符串

作者:互联网

import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import "dayjs/locale/zh-cn";
/** 设置语言为中文/
dayjs.locale("zh-cn");
dayjs.extend(relativeTime);

 /**返回时间戳(s)距当前时间的相对时间的字符串。精确到分 */
  getDataFromNow(unixNum: number) {
    return dayjs(dayjs.unix(unixNum).format("YYYY-MM-DD hh:mm")).fromNow();
  }

实例

标签:zh,cn,dayjs,relativeTime,locale,时间,字符串,import
来源: https://blog.csdn.net/weixin_42165378/article/details/121857075