【模板分享】统计今年已过多少天,当前周数

本贴最后更新于 746 天前,其中的信息可能已经沧海桑田

已过多少天


.action{$this_year :=now | date "2006"} 
.action{$next_year := add $this_year 1} 

.action{$this_year_first :=toDate "2006-01-02" ( nospace (cat $this_year "-01-01"))}
.action{$next_year_first :=toDate "2006-01-02" ( nospace (cat $next_year "-01-01"))}

.action{$pass := add (div (now.Sub $this_year_first).Hours 24) 1}
.action{$countdown := (div ($next_year_first.Sub now).Hours 24)}
> 今年已过了.action{$pass}天,距离.action{$next_year}年还有 .action{$countdown} 天

当前周数

.action{$this_year :=now | date "2006"} 

.action{$this_year_first :=toDate "2006-01-02" ( nospace (cat $this_year "-01-01"))}
.action{$this_year_last :=toDate "2006-01-02" ( nospace (cat $this_year "-12-31"))}

.action{$dayDict := dict "Mon" 1 "Tue" 2 "Wed" 3 "Thu" 4 "Fri" 5 "Sat" 6 "Sun" 7} 
.action{$firstDay := get $dayDict ($this_year_first  | date "Mon")}
.action{$pass_days := div (now.Sub $this_year_first ).Hours 24}

.action{$week := div (add $pass_days $firstDay) 7}
.action{$remain :=mod (add $pass_days $firstDay) 7}
.action{if not (eq $remain 0)}
.action{$week = add $week 1}
.action{end}


.action{$all_days := div ($this_year_last.Sub  $this_year_first ).Hours 24}
.action{$all_week := div (add $all_days  $firstDay) 7}
.action{$remain :=mod (add $all_days $firstDay) 7}
.action{if not (eq $remain 0)}
.action{$all_week = add $all_week 1}
.action{end}


现在已经第.action{$week}周/.action{$all_week}周

合并


.action{$this_year :=now | date "2006"} 
.action{$next_year := add $this_year 1} 

.action{$this_year_first :=toDate "2006-01-02" ( nospace (cat $this_year "-01-01"))}
.action{$this_year_last :=toDate "2006-01-02" ( nospace (cat $this_year "-12-31"))}

.action{$next_year_first :=toDate "2006-01-02" ( nospace (cat $next_year "-01-01"))}

.action{/* 1、正数和倒数*/}
.action{$pass := add (div (now.Sub $this_year_first).Hours 24) 1}
.action{$countdown := (div ($next_year_first.Sub now).Hours 24)}



.action{/* 2、统计周数*/}
.action{/* 2.1、已过多少周*/}
.action{$dayDict := dict "Mon" 1 "Tue" 2 "Wed" 3 "Thu" 4 "Fri" 5 "Sat" 6 "Sun" 7} 
.action{$firstDay := get $dayDict ($this_year_first  | date "Mon")}
.action{$pass_days := div (now.Sub $this_year_first ).Hours 24}

.action{$week := div (add $pass_days $firstDay) 7}
.action{$remain :=mod (add $pass_days $firstDay) 7}
.action{if not (eq $remain 0)}
.action{$week = add $week 1}
.action{end}

.action{/* 2.2、已过多少周*/}
.action{$all_days := div ($this_year_last.Sub  $this_year_first ).Hours 24}
.action{$all_week := div (add $all_days  $firstDay) 7}
.action{$remain :=mod (add $all_days $firstDay) 7}
.action{if not (eq $remain 0)}
.action{$all_week = add $all_week 1}
.action{end}

> 今年已过了.action{$pass}天,距离.action{$next_year}年还有 .action{$countdown} 天,现在已经第.action{$week}周/.action{$all_week}周
  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    18611 引用 • 69256 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • zh2021 1 评论

    请问这个怎么用呢?

    板文件夹下,新建一个 md 文件,粘贴相应内容,在思源用斜杆命令调用模板
    Achuan-2
Achuan-2
给时间以生命而不是给生命以时间,思源笔记使用分享 https://www.yuque.com/achuan-2/siyuan