小程序端日期时间显示格式
This commit is contained in:
@@ -20,27 +20,23 @@ function formatMoney(amount: number) {
|
|||||||
return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 中国时区展示:2026年8月3日 13点45分 */
|
/** 与权益「历史记录」一致:2026-08-03 13:53:03(Asia/Shanghai) */
|
||||||
function formatChinaDateTime(input?: string | null) {
|
function formatChinaDateTime(input?: string | null) {
|
||||||
const d = input ? new Date(input) : new Date();
|
const d = input ? new Date(input) : new Date();
|
||||||
if (Number.isNaN(d.getTime())) return '—';
|
if (Number.isNaN(d.getTime())) return '—';
|
||||||
const parts = new Intl.DateTimeFormat('zh-CN', {
|
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||||
timeZone: 'Asia/Shanghai',
|
timeZone: 'Asia/Shanghai',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'numeric',
|
month: '2-digit',
|
||||||
day: 'numeric',
|
day: '2-digit',
|
||||||
hour: 'numeric',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
hour12: false,
|
hour12: false,
|
||||||
}).formatToParts(d);
|
}).formatToParts(d);
|
||||||
const get = (type: Intl.DateTimeFormatPartTypes) =>
|
const get = (type: Intl.DateTimeFormatPartTypes) =>
|
||||||
parts.find((p) => p.type === type)?.value ?? '';
|
parts.find((p) => p.type === type)?.value ?? '';
|
||||||
const year = get('year');
|
return `${get('year')}-${get('month')}-${get('day')} ${get('hour')}:${get('minute')}:${get('second')}`;
|
||||||
const month = String(Number(get('month')));
|
|
||||||
const day = String(Number(get('day')));
|
|
||||||
const hour = String(Number(get('hour')));
|
|
||||||
const minute = get('minute').padStart(2, '0');
|
|
||||||
return `${year}年${month}月${day}日 ${hour}点${minute}分`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function StarRating({
|
function StarRating({
|
||||||
|
|||||||
Reference in New Issue
Block a user