微信小程序怎么实现日历的年视图功能

微信小程序怎么实现日历的年视图功能,第1张

因为日历是系统自带的,所以读写它一定要申请权限,也就是在AndroidManifestxml加如下两行代码(一个读一个写):

<uses-permission android:name="androidpermissionREAD_CALENDAR"/>

<uses-permission android:name="androidpermissionWRITE_CALENDAR"/>

Android中日历用了三个URL,分别是日历用户的URL,事件的URL,事件提醒URL,三个URL在Android21之前是如下的样子:

calanderURL = "content://calendar/calendars";

calanderEventURL = "content://calendar/events";

calanderRemiderURL= "content://calendar/reminders";

但是在Android22版本以后,三个URL有了改变,变成如下的样子:

calanderURL = "content://comandroidcalendar/calendars";

calanderEventURL = "content://comandroidcalendar/events";

calanderRemiderURL = "content://comandroidcalendar/reminders";

简单的Demo,按照我的步骤一步一步的来:

第一步:新建一个Android工程命名为CalendarDemo

第二步:修改mainxml布局文件,增加了三个按钮,代码如下:

<xml version="10" encoding="utf-8">

<LinearLayout xmlns:android=">

在桌面上双指捏合,进入桌面编辑状态。

2、点击窗口小工具,然后可以向左滑动查看所有小工具。

3、部分小工具(如天气)会有多种样式,点击该图标可以展开所有的样式。向右滑动展开的样式,可以收拢。

4、点击需要的小工具图标,即可将其添加到当前屏幕。如果当前屏幕没有空间,您可以长按并拖动该图标,将其添加到其它屏幕。

用VB做万年历,非常关键点就是农历写法,参考代码如下:

#Region " 返回农历 "

'返回农历

'cCalendarMaxSupportedDateTime 返回支持的最大日期,即2101-1-28

'cCalendarMinSupportedDateTime 返回支持的最小日期,即190-2-19

Private cCalendar As New SystemGlobalizationChineseLunisolarCalendar

Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String

cCalendar = New SystemGlobalizationChineseLunisolarCalendar

Dim lyear As Integer = cCalendarGetYear(sDateTime)

Dim lmonth As Integer = cCalendarGetMonth(sDateTime)

Dim lday As Integer = cCalendarGetDayOfMonth(sDateTime)

Dim lweek As Integer = cCalendarGetDayOfWeek(sDateTime)

'获取闰月, 0 则表示没有闰月

Dim leapMonth As Integer = cCalendarGetLeapMonth(lyear)

Dim isleap As Boolean = False

If (leapMonth > 0) Then

If (leapMonth = lmonth) Then

'闰月

isleap = True

lmonth = lmonth - 1

ElseIf (lmonth > leapMonth) Then

lmonth = lmonth - 1

End If

End If

Return StringConcat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))

End Function

'十天干

Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}

'十二地支

Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}

'十二生肖

Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}

'农历月

Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}

'农历日

Private days1 As String() = {"初", "十", "廿", "三"}

Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}

'返回农历年(天干 地支 生肖)

Private Function GetLunisolarYear(ByVal year As Integer) As String

GetLunisolarYear = ""

If (year > 3) Then

Dim tgIndex As Integer = (year - 4) Mod 10

Dim dzIndex As Integer = (year - 4) Mod 12

Return tiangan(tgIndex) & dizhi(dzIndex) & "[" & shengxiao(dzIndex) & "]"

End If

'无效的年份!

End Function

'返回生肖

Private Function GetShengXiao(ByVal sDateTime As Date) As String

Return shengxiao(cCalendarGetTerrestrialBranch(cCalendarGetSexagenaryYear(sDateTime)) - 1)

End Function

'返回农历月

Private Function GetLunisolarMonth(ByVal month As Integer) As String

GetLunisolarMonth = ""

If (month < 13 AndAlso month > 0) Then

Return months(month - 1)

End If

'无效的月份!

End Function

'返回农历日

Private Function GetLunisolarDay(ByVal day As Integer) As String

GetLunisolarDay = ""

If (day > 0 AndAlso day < 32) Then

If (day <> 20 AndAlso day <> 30) Then

Return StringConcat(days1((day - 1) \ 10), days((day - 1) Mod 10))

Else

Return StringConcat(days((day - 1) \ 10), days1(1))

End If

End If

'无效的日!

End Function

#End Region

以上就是关于微信小程序怎么实现日历的年视图功能全部的内容,包括:微信小程序怎么实现日历的年视图功能、微信小程序 vant日历自定义文案、华为nova7桌面小程序日历表怎么没有年份等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9332222.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存