• javascript生成ics、日程、日历


    实例、代码、资料

    实例1

    BEGIN:VCALENDAR
    METHOD:PUBLISH
    VERSION:2.0
    X-WR-CALNAME:阿斯顿发
    X-APPLE-CALENDAR-COLOR:#540EB9
    BEGIN:VEVENT
    UID:1668753387035
    SUMMARY:修改
    DTSTART;VALUE=DATE-TIME:20231124T04:30:00Z
    DTEND;VALUE=DATE-TIME:20231124T14:30:00Z
    DESCRIPTION:主要内容中文修改
    LOCATION:地点
    END:VEVENT
    END:VCALENDAR
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    BEGIN:VCALENDAR
    METHOD:PUBLISH
    VERSION:2.0
    X-WR-CALNAME:百融云创
    X-APPLE-CALENDAR-COLOR:#540EB9
    BEGIN:VEVENT
    UID:
    SUMMARY:11月工作计划
    DTSTART;VALUE=DATE:20221118T084000Z
    DTEND;VALUE=DATE:20221118T085000Z
    DESCRIPTION:阿斯顿发
    LOCATION:阿斯顿发
    END:VEVENT
    END:VCALENDAR
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    实例2

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/style.css" rel="stylesheet">
        <script>
          const icsMeg2 = `
          BEGIN:VCALENDAR
          METHOD:PUBLISH
          VERSION:2.0
          X-WR-CALNAME:阿斯顿发
          X-APPLE-CALENDAR-COLOR:#540EB9
          BEGIN:VEVENT
          UID:${Date.now()}
          SUMMARY:${Date.now()}
          DTSTART;VALUE=DATE:20221118T084000Z
          DTEND;VALUE=DATE:20221118T085000Z
          DESCRIPTION:阿斯顿发
          LOCATION:阿斯顿发
          END:VEVENT
          END:VCALENDAR`;
          // window.open('data:text/calendar;charset=utf8,' + icsMSG);
          const blob = new Blob([icsMSG], { type: 'text/calendar' });
          const link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = 'Calendar2.ics';
          link.click();
        </script>
      </head>
      <body>
        <div>
          asdfasdfsfd
          <a href="">阿斯顿发送到发</a>
        </div>
      </body>
    </html>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    项目中代码实现

    handleAddCalendar(item) {
          const startTime = item.startTime ? moment(item.meetingDate + ' ' + item.startTime).format('YYYYMMDDTHH:mm:ss') + 'Z' : moment(item.meetingDate).format('YYYYMMDDTHH:mm:ss') + 'Z';
          const endTime = item.endTime ? moment(item.meetingDate + ' ' + item.endTime).format('YYYYMMDDTHH:mm:ss') + 'Z' : moment(item.meetingDate).format('YYYYMMDDTHH:mm:ss') + 'Z';
          const title = this.language === 'e' ? `${item.enMeetingTitle}` : `${item.cnMeetingTitle}`;
          const content = this.language === 'e' ? `${item.enContent}` : `${item.cnContent}`;
          const place = this.language === 'e' ? `${item.enMeetingPlace}` : `${item.cnMeetingPlace}`;
          const icsMsg = 'BEGIN:VCALENDAR\n' +
            'METHOD:PUBLISH\n' +
            'VERSION:2.0\n' +
            'X-WR-CALNAME:百融云创\n' +
            'X-APPLE-CALENDAR-COLOR:#540EB9\n' +
            'BEGIN:VEVENT\n' +
            `UID:${Date.now()}\n` +
            `SUMMARY:${title}\n` +
            `DTSTART;VALUE=DATE-TIME:${startTime}\n` +
            `DTEND;VALUE=DATE-TIME:${endTime}\n` +
            `DESCRIPTION:${content}\n` +
            `LOCATION:${place}\n` +
            'END:VEVENT\n' +
            'END:VCALENDAR';
          const blob = new Blob([icsMsg], { type: 'text/calendar' });
          const link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = `${title}.ics`;
          link.click();
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    参考资料

  • 相关阅读:
    GIT使用(踩坑)
    日志框架log4j升级至log4j2
    MySQL如何获取binlog的开始时间和结束时间
    【Logback+Spring-Aop】实现全面生态化的全链路日志追踪系统服务插件「Logback-MDC篇」
    实例方法(instance method)、类方法、构造方法(三)
    终于理解 Spring Boot为什么如此受青睐 HikariCP了,这图太透彻
    LeetCode20 有效的括号
    vim基本操作
    P3-Python学习当中的两大法宝函数
    强化学习在无人车领域的应用与展望
  • 原文地址:https://blog.csdn.net/eadela/article/details/127922791