|
|
@@ -59,6 +59,50 @@ const tool = {
|
|
|
if (withTime) return Y + M + D + h + m + s
|
|
|
return Y + M + D
|
|
|
},
|
|
|
+ convertToNigeriaTime(timestamp) {
|
|
|
+ timestamp = this.normalizeTimestamp(timestamp)
|
|
|
+ const options = {
|
|
|
+ timeZone: 'Africa/Lagos',
|
|
|
+ year: 'numeric',
|
|
|
+ month: '2-digit',
|
|
|
+ day: '2-digit',
|
|
|
+ hour: '2-digit',
|
|
|
+ minute: '2-digit',
|
|
|
+ second: '2-digit',
|
|
|
+ hour12: false // 24-hour format
|
|
|
+ };
|
|
|
+ const formatter = new Intl.DateTimeFormat('en-GB', options);
|
|
|
+ const formattedDate = formatter.format(new Date(timestamp));
|
|
|
+
|
|
|
+ // Reformatting to YYYY-MM-DD HH:mm:ss
|
|
|
+ const [date, time] = formattedDate.split(', ');
|
|
|
+ const [day, month, year] = date.split('/');
|
|
|
+ return `${year}-${month}-${day} ${time}`;
|
|
|
+ },
|
|
|
+ convertToNigeriaDayTime(timestamp) {
|
|
|
+ timestamp = this.normalizeTimestamp(timestamp)
|
|
|
+ const options = {
|
|
|
+ timeZone: 'Africa/Lagos',
|
|
|
+ year: 'numeric',
|
|
|
+ month: '2-digit',
|
|
|
+ day: '2-digit',
|
|
|
+ hour: '2-digit',
|
|
|
+ minute: '2-digit',
|
|
|
+ second: '2-digit',
|
|
|
+ hour12: false // 24-hour format
|
|
|
+ };
|
|
|
+ const formatter = new Intl.DateTimeFormat('en-GB', options);
|
|
|
+ const formattedDate = formatter.format(new Date(timestamp));
|
|
|
+
|
|
|
+ // Reformatting to YYYY-MM-DD HH:mm:ss
|
|
|
+ const [date, time] = formattedDate.split(', ');
|
|
|
+ const [day, month, year] = date.split('/');
|
|
|
+ return `${year}-${month}-${day}`;
|
|
|
+ },
|
|
|
+ normalizeTimestamp(timestamp) {
|
|
|
+ // 如果小于毫秒级最小值,认为是秒级时间戳
|
|
|
+ return timestamp < 1000000000000 ? timestamp * 1000 : timestamp;
|
|
|
+ },
|
|
|
/**
|
|
|
* 处理错误结果
|
|
|
* @param error
|