当前位置: 首页 > wzjs >正文

哪里有南宁网站建设ks刷粉网站推广马上刷

哪里有南宁网站建设,ks刷粉网站推广马上刷,娱乐城网站建设,西安网站策划用字符串构造datetime Typst自带的datetime需要使用字典形式构造。我觉得不太好看,所以编写函数用字符串构造datetime。 实现 // 日期函数 #let day(date_str) {let(y,m,d) date_str.split("-")return datetime(year:int(y),month:int(m),day:int(d)…

用字符串构造datetime

Typst自带的datetime需要使用字典形式构造。我觉得不太好看,所以编写函数用字符串构造datetime

实现

// 日期函数
#let day(date_str) = {let(y,m,d) = date_str.split("-")return datetime(year:int(y),month:int(m),day:int(d),)
}// 时间函数
#let time(time_str) = {let(h,m,s) = time_str.split(":")return datetime(hour:int(h),minute:int(m),second:int(s),)
}// 日期时间函数
#let day_time(date_time_str) = {let(date_str,time_str) = date_time_str.split(" ")let(y,m,d) = date_str.split("-")let(h,mt,s) = time_str.split(":")return datetime(year:int(y),month:int(m),day:int(d),hour:int(h),minute:int(mt),second:int(s),)
}

使用也很简单,调用函数即可。

#day("2025-10-11")  // datetime(year: 2025,month:10,day: 11)
#time("12:09:08")   // datetime(hour:12,minute:9,second:8)
#day_time("2025-10-12 11:08:09")

月历和年历

发现自己很想用Typst搞日历,第三方包cineca的日历不持支中文,于是搜出几年前在Godot3.5编写的日期时间函数库,实现了Typst的版本,并制作了基于表格的月历和年历函数。

// 判断是否是闰年(leap year)
#let is_leap_year(year) = {let bol = falseif calc.rem(year,4) == 0 {bol = trueif calc.rem(year,100) == 0 {  // 年份是100的倍数if calc.rem(year,400) == 0 {  // 必须是400的整数倍bol = true} else {bol = false}}}return bol
}// 返回某年的某月共有多少天	
#let get_month_day_count(year,month) = {let day_count = 0if month == 2 {if is_leap_year(year){ //闰年day_count = 29} else {day_count = 28}		} else if month in (1,3,5,7,8,10,12) { // 大月day_count = 31} else if month in (4,6,9,11){         // 小月day_count = 30}return day_count
}// 返回某年共有多少天	
#let get_year_day_count(year) = {let day_count = 0for i in range(12){day_count += get_month_day_count(year,i+1)}return day_count
}// 获取某年某月第一天星期几(数字)
#let get_first_weekday(year,month) = {let d = str(year) + "-" + str(month) + "-01"return day(d).weekday()
}// 获取某年某月第一天星期几(汉字)
#let get_first_weekday_name(year,month) = {import "@preview/a2c-nums:0.0.1": int-to-cn-numlet w = get_first_weekday(year,month)if w in range(1,7) {return int-to-cn-num(w)} else {return "日"}
}// 获取月历数据序列
#let get_month_list(year,month) = {let w = get_first_weekday(year,month)   // 本月第一天周几let m = get_month_day_count(year,month) // 本月天数let s = 42 - m // 剩余填充let list = ()// 填充前空白if w in range(1,7) {for i in range(1,w+1) {list.push([])}s -= w}// 填充日数for i in range(1,m+1) {list.push([#i])}// 填充后空白for i in range(1,s) {list.push([ \ ])}return list
}// 显示月历
#let show_month(year,month,show_year:true
) = {[#box[#align(center)[#if show_year [#year] #month]#table(columns:7,[],[],[],[],[],[],[],..get_month_list(year,month))]]
}// 显示某年的所有月份
#let show_months(year) = {align(center)[#text(36pt,font: "Microsoft Sans Serif")[#year]]for i in range(1,13) {show_month(year,i,show_year: false)}
}

你可以使用show_month显示某年某月的月历:

#show_month(2025,3)   // 显示2025年3月的月历
#show_months(2025)    // 显示2025年整年的月历

在这里插入图片描述

在这里插入图片描述

期间

两个datetime相减,或者使用duration()函数构造,可以创建一个duration,它代表时间差或持续的一段时间。

duration(seconds: int,minutes: int,hours: int,days: int,weeks: int,
) -> duration

求两个日期之间的差值

#(day("2025-6-1") - day("2025-5-1")).days()    \\ 31d
#(day("2025-6-1") - day("2025-5-1")).hours()   \\ 744h
#(day("2025-6-1") - day("2025-5-1")).seconds() \\ 2678400s

倒计时

可以用duration来创建倒计时。

完整代码

我将完整代码保存为mDateTime.typ,并在使用时用import形式导入:

#import "mDateTime.typ":*

完整代码如下:

// 日期函数
#let day(date_str) = {let(y,m,d) = date_str.split("-")return datetime(year:int(y),month:int(m),day:int(d),)
}// 时间函数
#let time(time_str) = {let(h,m,s) = time_str.split(":")return datetime(hour:int(h),minute:int(m),second:int(s),)
}// 日期时间函数
#let day_time(date_time_str) = {let(date_str,time_str) = date_time_str.split(" ")let(y,m,d) = date_str.split("-")let(h,mt,s) = time_str.split(":")return datetime(year:int(y),month:int(m),day:int(d),hour:int(h),minute:int(mt),second:int(s),)
}// 判断是否是闰年(leap year)
#let is_leap_year(year) = {let bol = falseif calc.rem(year,4) == 0 {bol = trueif calc.rem(year,100) == 0 {  // 年份是100的倍数if calc.rem(year,400) == 0 {  // 必须是400的整数倍bol = true} else {bol = false}}}return bol
}// 返回某年的某月共有多少天	
#let get_month_day_count(year,month) = {let day_count = 0if month == 2 {if is_leap_year(year){ //闰年day_count = 29} else {day_count = 28}		} else if month in (1,3,5,7,8,10,12) { // 大月day_count = 31} else if month in (4,6,9,11){         // 小月day_count = 30}return day_count
}// 返回某年共有多少天	
#let get_year_day_count(year) = {let day_count = 0for i in range(12){day_count += get_month_day_count(year,i+1)}return day_count
}// 获取某年某月第一天星期几(数字)
#let get_first_weekday(year,month) = {let d = str(year) + "-" + str(month) + "-01"return day(d).weekday()
}// 获取某年某月第一天星期几(汉字)
#let get_first_weekday_name(year,month) = {import "@preview/a2c-nums:0.0.1": int-to-cn-numlet w = get_first_weekday(year,month)if w in range(1,7) {return int-to-cn-num(w)} else {return "日"}
}// 获取月历数据序列
#let get_month_list(year,month) = {let w = get_first_weekday(year,month)   // 本月第一天周几let m = get_month_day_count(year,month) // 本月天数let s = 42 - m // 剩余填充let list = ()// 填充前空白if w in range(1,7) {for i in range(1,w+1) {list.push([])}s -= w}// 填充日数for i in range(1,m+1) {list.push([#i])}// 填充后空白for i in range(1,s) {list.push([ \ ])}return list
}// 显示月历
#let show_month(year,month,show_year:true
) = {[#box[#align(center)[#if show_year [#year] #month]#table(columns:7,[],[],[],[],[],[],[],..get_month_list(year,month))]]
}// 显示某年的所有月份
#let show_months(year) = {align(center)[#text(36pt,font: "Microsoft Sans Serif")[#year]]for i in range(1,13) {show_month(year,i,show_year: false)}
}
http://www.dtcms.com/wzjs/443956.html

相关文章:

  • 网站seo排名优化软件广州各区正在进一步优化以下措施
  • 网站建设专业导航网站b2b平台
  • 专业建设金融行业网站的公司网页设计用什么软件做
  • 派出所web网站建设策划案如何自己建一个网站
  • 网站后台的网址忘记了湖南百度推广开户
  • 浙江建设厅网站那三类人员高质量关键词搜索排名
  • 宁波网站推广优化联系电话网店运营推广方案
  • 做微商能利用的网站有哪些问题手机优化大师官方免费下载
  • 北京网站优化网安卓aso优化
  • 东莞做网站 9353周口网站制作
  • 柳州网站优化公司成都网站建设软件
  • 有什么网站可以做运动百度推广一条资源多少钱
  • 百度怎样做网站排名往前免费的seo教程
  • 淄博网站制作网页公司创建网站需要多少资金
  • 腾讯云域名如何建设网站免费引流app下载
  • 优秀简洁网站设计36优化大师下载安装
  • 邮箱网站怎么做给公司建网站需要多少钱
  • 如何在线上注册公司陕西seo快速排名
  • 网站建设怎么选择优化网站推广教程整站
  • 科技公司网站 asp源码站长之家seo信息
  • wordpress主题响应式360网站关键词排名优化
  • 做网站可以申请国家补助吗长沙百家号seo
  • 新余做网站的排名第一的玉米品种
  • 做门的网站建设客户管理软件哪个好用
  • c 建设web网站的流程怎么做seo网站关键词优化
  • 建设项目环境影响登记网站天津关键字优化
  • 党建设计图片太原seo网络优化招聘网
  • 老外做牛排的视频网站野狼seo团队
  • 哈尔滨营销网站建设公司怎样优化关键词到首页
  • phpwind 手机网站模板最新网络推广平台