ios 日历同步提醒事项-修改

原文地址

【ios】日历同步到提醒事项+打卡功能 - 汀力的文章 - 知乎

这篇是自动转换IOS的日历到提醒事项,在提醒事项中打钩后自动同步到日历。

上面文章不是我的,我只是修改了一下转换范围的代码,本章也只放日期部分的代码,完整代码去作者文章里看哈,像这样的感觉 ↓

 要改变的内容:代码最前面的这段日期

 ↓ 这是原版的,原版是把之后一个月的内容都转变了

var dur_month = 1

const startDate = new Date()
startDate.setMonth(startDate.getMonth() - dur_month)
console.log(`日历的开始时间 ${startDate.toLocaleDateString()}`)

const endDate = new Date()
endDate.setMonth(endDate.getMonth() + dur_month)
console.log(`日历的结束时间 ${endDate.toLocaleDateString()}`)

本周版本 :转换这周一到这周末的日程

let date = new Date()
//周一00:00:00
startDate=new Date(new Date(date).getTime() - (3600 * 1000 * 24 * (new Date(date).getDay() == 0 ? 7 : new Date(date).getDay()-1)))
startDate1 = startDate.setHours(0)
startDate2 = startDate.setMinutes(0)
startDate3 = startDate.setSeconds(0)
startDate4 = startDate.setMilliseconds(0)
console.log(`日历的开始时间 ${startDate.toLocaleDateString()}`)
// console.log(startDate)
//周日23:59:59
endDate=new Date(new Date(date).getTime()+(3600*1000*24 * (new Date(date).getDay()==0 ? 0:7- new Date(date).getDay(date))))
endDate1 = endDate.setHours(23)
endDate2 = endDate.setMinutes(59)
endDate3 = endDate.setSeconds(59)
endDate4 = endDate.setMilliseconds(999)
console.log(`日历的结束时间 ${endDate.toLocaleDateString()}`)
// console.log(endDate)

今日版本:只转换今天的日程

let date = new Date()
//今天00:00:00
startDate=new Date(new Date(date).getTime() - (3600 * 1000 * 24 * (new Date(date).getDay() == 0 ? 7 : new Date(date).getDay()-3)))
startDate1 = startDate.setHours(0)
startDate2 = startDate.setMinutes(0)
startDate3 = startDate.setSeconds(0)
startDate4 = startDate.setMilliseconds(0)
console.log(`日历的开始时间 ${startDate.toLocaleDateString()}`)
// console.log(startDate)
//今天23:59:59
endDate=new Date(new Date(date))
endDate1 = endDate.setHours(23)
endDate2 = endDate.setMinutes(59)
endDate3 = endDate.setSeconds(59)
endDate4 = endDate.setMilliseconds(999)
console.log(`日历的结束时间 ${endDate.toLocaleDateString()}`)
// console.log(endDate)

上周一到今天:

let date = new Date()
//上周周一0:0:0
startDate=new Date(new Date(date).getTime() - (3600 * 1000 * 24 * (new Date(date).getDay() == 0 ? 7 : new Date(date).getDay()+6)))
startDate1 = startDate.setHours(0)
startDate2 = startDate.setMinutes(0)
startDate3 = startDate.setSeconds(0)
startDate4 = startDate.setMilliseconds(0)
console.log(`日历的开始时间 ${startDate.toLocaleDateString()}`)
console.log(startDate)
//今晚23:59:59
endDate=new Date(new Date(date))
endDate1 = endDate.setHours(23)
endDate2 = endDate.setMinutes(59)
endDate3 = endDate.setSeconds(59)
endDate4 = endDate.setMilliseconds(999)
console.log(`日历的结束时间 ${endDate.toLocaleDateString()}`)
console.log(endDate)

 提醒:本文只适用于作者2023-01-21之前的版本,如果她改了原代码可能用不了哈

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值