如何将将2024-03-05T00:00:00+00:00格式的时间转换成方便阅读的年月日展示?

如何将将2024-03-05T00:00:00+00:00格式的时间转换成方便阅读的年月日展示?

HarmonyOS
2024-07-05 17:48:07
691浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
噜啦噜啦嘞噜啦嘞
export function formatISODateToYYYYMMDD(isoDateString: string): string {
  if (isoDateString) {
    // 解析 ISO 格式的日期时间字符串为 Date 对象
    const date = new Date(isoDateString);

    // 从 Date 对象中提取年月日信息
    const year = date.getUTCFullYear();
    const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以加 1,并使用 padStart 确保为两位数
    const day = String(date.getUTCDate()).padStart(2, '0'); // 使用 padStart 确保为两位数


    if (new Date().getFullYear() === year) {
      //今年
      return `${month}月${day}日`;
    }
    return `${year}年${month}月${day}日`;

  }
  return ""

}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
分享
微博
QQ
微信
回复
2024-07-06 10:43:12
相关问题
HarmonyOS TextTimer60秒倒计时显示成00
899浏览 • 1回复 待解决
如何将某个时间转换成距现在时间
1230浏览 • 1回复 待解决
如何将AndroidAPP转换成鸿蒙
347浏览 • 1回复 已解决
HarmonyOS 如何将汉字转换成拼音
977浏览 • 1回复 待解决
如何将文件转换成字符串
1122浏览 • 1回复 待解决
如何将时间转换为日期格式时间
4337浏览 • 1回复 待解决
请问如何将openblock文件转换成exe文件
3131浏览 • 0回复 待解决
HarmonyOS 日期如何转换成毫秒
727浏览 • 1回复 待解决
HarmonyOS 图片转换成ImageBitmap
1006浏览 • 1回复 待解决
HarmonyOS 页面转换成图片
551浏览 • 1回复 待解决
如何base64转换成图片?
11527浏览 • 2回复 待解决
HarmonyOS Object怎么转换成map
713浏览 • 1回复 待解决