Showing
2 changed files
with
22 additions
and
1 deletions
| @@ -509,6 +509,26 @@ export class DateTimeUtils { | @@ -509,6 +509,26 @@ export class DateTimeUtils { | ||
| 509 | } | 509 | } |
| 510 | return num; | 510 | return num; |
| 511 | } | 511 | } |
| 512 | + | ||
| 513 | + /** | ||
| 514 | + * 去除发布日期前导零 | ||
| 515 | + * @param dateTimeString 2024年01月01日 00:00 | ||
| 516 | + * @returns 2024年1月1日 00:00 | ||
| 517 | + */ | ||
| 518 | + static removeTrailingZeros(dateTimeString: string) { | ||
| 519 | + // 分割日期时间字符串 | ||
| 520 | + const [datePart, timePart] = dateTimeString.split(' '); | ||
| 521 | + // 分割日期 | ||
| 522 | + const [year, month, day] = datePart.match(/\d+/g); | ||
| 523 | + // 去除年和月后面的零 | ||
| 524 | + const trimmedMonth = parseInt(month, 10); | ||
| 525 | + const trimmedDay = parseInt(day, 10); | ||
| 526 | + | ||
| 527 | + // 重新组合日期时间字符串 | ||
| 528 | + const newDateTimeString = `${year}年${trimmedMonth}月${trimmedDay}日 ${timePart}`; | ||
| 529 | + | ||
| 530 | + return newDateTimeString; | ||
| 531 | + } | ||
| 512 | } | 532 | } |
| 513 | 533 | ||
| 514 | // const dateTimeUtils = new DateTimeUtils() | 534 | // const dateTimeUtils = new DateTimeUtils() |
| @@ -204,7 +204,8 @@ export struct ImageAndTextPageComponent { | @@ -204,7 +204,8 @@ export struct ImageAndTextPageComponent { | ||
| 204 | this.contentDetailData = detailBeans; | 204 | this.contentDetailData = detailBeans; |
| 205 | let dateTime = | 205 | let dateTime = |
| 206 | DateTimeUtils.parseDate(this.contentDetailData[0]?.publishTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN); | 206 | DateTimeUtils.parseDate(this.contentDetailData[0]?.publishTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN); |
| 207 | - this.publishTime = DateTimeUtils.formatDate(dateTime, PATTERN_DATE_CN_RN) | 207 | + let _publishTime = DateTimeUtils.formatDate(dateTime, PATTERN_DATE_CN_RN) |
| 208 | + this.publishTime = DateTimeUtils.removeTrailingZeros(_publishTime) | ||
| 208 | if (this.contentDetailData[0]?.recommendShow === 1) { | 209 | if (this.contentDetailData[0]?.recommendShow === 1) { |
| 209 | this.getRecommend() | 210 | this.getRecommend() |
| 210 | } | 211 | } |
-
Please register or login to post a comment