Day.js转中文,并处理日期fromNow

下载npm install dayjs

import dayjs from "dayjs";

import relativeTime from "dayjs/plugin/relativeTime";

import "dayjs/locale/zh-cn";

dayjs.extend(relativeTime);

fromNow方法:

import dayjs from "dayjs";

import relativeTime from "dayjs/plugin/relativeTime";

import "dayjs/locale/zh-cn";

dayjs.extend(relativeTime);

// formNow
const getFromNow = (time) => {
  return (new Date(time)).locale("zh-cn").fromNow();
};

你可能感兴趣的:(javascript,java,前端,dayjs,fromNow)