优化日期展示及样式
This commit is contained in:
+8
-1
@@ -1,8 +1,15 @@
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
import timezone from "dayjs/plugin/timezone.js";
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
// 设置中文语言环境
|
||||
import 'dayjs/locale/zh-cn'
|
||||
dayjs.locale('zh-cn');
|
||||
// 获取文章的描述
|
||||
const getDescription = (post: any, num: number = 150) => (post.rendered ? post.rendered.html.replace(/<[^>]+>/g, "").replace(/\s+/g, "") : post.body.replace(/\n/g, "").replace(/#/g, "")).slice(0, num) || '暂无简介'
|
||||
//处理时间
|
||||
const fmtTime = (time: any, fmt: string = 'MMMM D, YYYY') => dayjs(time).format(fmt)
|
||||
const fmtTime = (time: any, fmt: string = 'MMMM D, YYYY') => dayjs(time).tz('America/New_York').format(fmt)
|
||||
// 处理日期
|
||||
const fmtDate = (time: string | Date) => {
|
||||
const now = dayjs();
|
||||
|
||||
Reference in New Issue
Block a user