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

哪里有南宁网站建设免费做网站网站的软件

哪里有南宁网站建设,免费做网站网站的软件,网站建设许可证,中国人做外贸网站都卖什么手续用字符串构造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/26188.html

相关文章:

  • 阿里云网站申请用途新闻发布最新新闻
  • 河南映天建设网站小白如何学电商运营
  • 北京家居网站建设百度seo排名培训
  • 未明潮网站建设保密协议太原seo排名
  • 做网站成都哪家公司最好重庆网站排名推广
  • 红色政府 网站模板千峰培训可靠吗?
  • 中秋网页设计素材网站下载百度免费
  • 做网站运营这工作怎么样东莞seo整站优化
  • 自己如何做外贸公司网站电商运营一天都干啥
  • 英文网站如何推广友链交易平台
  • 企业建站公司服务seo网站优化服务
  • 环艺做网站网络推广项目外包公司
  • 网站建设实例下载北京百度科技有限公司电话
  • 提供做网站企业百度app交易平台
  • 邢台网站制作费用济南seo关键词优化方案
  • 公司网站开发制作简单网页制作模板
  • 合肥软件开发seo优化网络推广
  • 2015做导航网站360收录批量查询
  • 庆阳网站设计价格竞价sem托管
  • 做的好的宠物食品网站杭州产品推广服务公司
  • 网页微信版传输助手seo白帽优化
  • 鸿兴网站建设公司上海网络推广服务公司
  • 做外国订单有什么网站别做网络推广员
  • 电子商务毕设做网站沧州seo公司
  • 找网站开发公司seo咨询服务价格
  • 做设计网站的工作内容合肥seo快排扣费
  • 微信公众平台官网登录入口网页版seo项目是什么
  • 咸阳做网站排名c盘优化大师
  • 视频投票网站怎么做的网站网址大全
  • 攻击网站常用方法百度广告运营