Skip to content

思源内置模板函数

函数名简介
FormatFloat ^3.0.12格式化输出浮点数
ISOWeek ^2.11.1获取日期对应的 ISO 8601 周数
WeekdayCN2 ^2.11.2获取日期对应的中文星期名称 (Sunday: "日")
WeekdayCN ^2.11.1获取日期对应的中文星期名称 (Sunday: "天")
Weekday ^2.11.1获取日期对应的星期编号 (Sunday: 0)
log ^2.11.3对数运算 logaN (返回 int64 类型)
logf ^2.11.3对数运算 logaN (返回 float64 类型)
parseTime ^1.5.5解析时间戳字符串
pow ^2.11.3指数运算 an (返回 int64 类型)
powf ^2.11.3指数运算 an (返回 float64 类型)

FormatFloat ^3.0.12

示例
text
=> {{FormatFloat "" 12345.6789}}
<= 12,345.68

=> {{FormatFloat "#" 12345.6789}}
<= 12345.678900000

=> {{FormatFloat "#." 12345.6789}}
<= 12346

=> {{FormatFloat "#,###" 12345.6789}}
<= 12345,679

=> {{FormatFloat "#.###" 12345.6789}}
<= 12345.679

=> {{FormatFloat "#,###." 12345.6789}}
<= 12,346

=> {{FormatFloat "#'###." 12345.6789}}
<= 12'346

=> {{FormatFloat "#,###.##" 12345.6789}}
<= 12,345.68

=> {{FormatFloat "#'###.##" 12345.6789}}
<= 12'345.68

=> {{FormatFloat "#,###.######" 12345.6789}}
<= 12,345.678900

=> {{FormatFloat "#'###.######" 12345.6789}}
<= 12'345.678900

ISOWeek ^2.11.1

示例
text
=> 2020-01-01 在 2020 年第 {{toDate "2006-01-02" "2020-01-01" | ISOWeek}} 周
<= 2020-01-01 在 2020 年第 1 周

=> 2021-01-01 在 2020 年第 {{toDate "2006-01-02" "2021-01-01" | ISOWeek}} 周
<= 2021-01-01 在 2020 年第 53 周

=> 2022-01-01 在 2021 年第 {{toDate "2006-01-02" "2022-01-01" | ISOWeek}} 周
<= 2022-01-01 在 2021 年第 52 周

=> 2023-01-01 在 2022 年第 {{toDate "2006-01-02" "2023-01-01" | ISOWeek}} 周
<= 2023-01-01 在 2022 年第 52 周

=> 2024-01-01 在 2024 年第 {{toDate "2006-01-02" "2024-01-01" | ISOWeek}} 周
<= 2024-01-01 在 2024 年第 1 周

WeekdayCN2 ^2.11.2

示例
text
=> 2024-01-01 星期{{toDate "2006-01-02" "2024-01-01" | WeekdayCN2}}
<= 2024-01-01 星期一

=> 2024-01-02 星期{{toDate "2006-01-02" "2024-01-02" | WeekdayCN2}}
<= 2024-01-02 星期二

=> 2024-01-03 星期{{toDate "2006-01-02" "2024-01-03" | WeekdayCN2}}
<= 2024-01-03 星期三

=> 2024-01-04 星期{{toDate "2006-01-02" "2024-01-04" | WeekdayCN2}}
<= 2024-01-04 星期四

=> 2024-01-05 星期{{toDate "2006-01-02" "2024-01-05" | WeekdayCN2}}
<= 2024-01-05 星期五

=> 2024-01-06 星期{{toDate "2006-01-02" "2024-01-06" | WeekdayCN2}}
<= 2024-01-06 星期六

=> 2024-01-07 星期{{toDate "2006-01-02" "2024-01-07" | WeekdayCN2}}
<= 2024-01-07 星期天

WeekdayCN ^2.11.1

示例
text
=> 2024-01-01 周{{toDate "2006-01-02" "2024-01-01" | WeekdayCN}}
<= 2024-01-01 周一

=> 2024-01-02 周{{toDate "2006-01-02" "2024-01-02" | WeekdayCN}}
<= 2024-01-02 周二

=> 2024-01-03 周{{toDate "2006-01-02" "2024-01-03" | WeekdayCN}}
<= 2024-01-03 周三

=> 2024-01-04 周{{toDate "2006-01-02" "2024-01-04" | WeekdayCN}}
<= 2024-01-04 周四

=> 2024-01-05 周{{toDate "2006-01-02" "2024-01-05" | WeekdayCN}}
<= 2024-01-05 周五

=> 2024-01-06 周{{toDate "2006-01-02" "2024-01-06" | WeekdayCN}}
<= 2024-01-06 周六

=> 2024-01-07 周{{toDate "2006-01-02" "2024-01-07" | WeekdayCN}}
<= 2024-01-07 周日

Weekday ^2.11.1

示例
text
=> {{toDate "2006-01-02" "2024-01-01" | Weekday}}
<= 1

=> {{toDate "2006-01-02" "2024-01-02" | Weekday}}
<= 2

=> {{toDate "2006-01-02" "2024-01-03" | Weekday}}
<= 3

=> {{toDate "2006-01-02" "2024-01-04" | Weekday}}
<= 4

=> {{toDate "2006-01-02" "2024-01-05" | Weekday}}
<= 5

=> {{toDate "2006-01-02" "2024-01-06" | Weekday}}
<= 6

=> {{toDate "2006-01-02" "2024-01-07" | Weekday}}
<= 0

log ^2.11.3

  • 介绍
    • 对数运算 logaN
    • 运算结果向下取整
  • 函数定义 func log(N, a interface{}) int64
    • 参数
      1. N: interface{} 真数
      2. a: interface{} 底数
    • 返回值
      1. int64 向下取整后的对数运算结果 logaN
  • 参考
示例
text
=> {{log 10 10}}
<= 1

=> {{log 10.0 10.0}}
<= 1

=> {{log "10" "10"}}
<= 1

=> {{log "10.0" "10.0"}}
<= 1

=> {{log 99 10}}
<= 1

=> {{log 100 10}}
<= 2

=> {{log 101 10}}
<= 2

=> {{log 0 10}}
<= -9223372036854775808

=> {{log 10 0}}
<= 0

=> {{log -10 10}}
<= -9223372036854775808

=> {{log 10 -10}}
<= -9223372036854775808

=> {{log -10 -10}}
<= -9223372036854775808

logf ^2.11.3

示例
text
=> {{logf 10 10}}
<= 1

=> {{logf 10.0 10.0}}
<= 1

=> {{logf "10" "10"}}
<= 1

=> {{logf "10.0" "10.0"}}
<= 1

=> {{logf 99 10}}
<= 1.9956351945975497

=> {{logf 100 10}}
<= 2

=> {{logf 101 10}}
<= 2.0043213737826426

=> {{logf 0 10}}
<= -Inf

=> {{logf 10 0}}
<= -0

=> {{logf -10 10}}
<= NaN

=> {{logf 10 -10}}
<= NaN

=> {{logf -10 -10}}
<= NaN

parseTime ^1.5.5

示例
text
=> {{FormatFloat "" 12345.6789}}
<= 12,345.68

=> {{parseTime "May 8, 2009 5:57:51 PM"}}
<= 2009-05-08 17:57:51 +0000 UTC

=> {{parseTime "oct 7, 1970"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "oct 7, '70"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "oct. 7, 1970"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "oct. 7, 70"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "Mon Jan  2 15:04:05 2006"}}
<= 2006-01-02 15:04:05 +0000 UTC

=> {{parseTime "Mon Jan  2 15:04:05 MST 2006"}}
<= 2006-01-02 15:04:05 +0000 MST

=> {{parseTime "Mon Jan 02 15:04:05 -0700 2006"}}
<= 2006-01-02 15:04:05 -0700 -0700

=> {{parseTime "Monday, 02-Jan-06 15:04:05 MST"}}
<= 2006-01-02 15:04:05 +0000 MST

=> {{parseTime "Mon, 02 Jan 2006 15:04:05 MST"}}
<= 2006-01-02 15:04:05 +0000 MST

=> {{parseTime "Tue, 11 Jul 2017 16:28:13 +0200 (CEST)"}}
<= 2017-07-11 16:28:13 +0200 +0200

=> {{parseTime "Mon, 02 Jan 2006 15:04:05 -0700"}}
<= 2006-01-02 15:04:05 -0700 -0700

=> {{parseTime "Mon 30 Sep 2018 09:09:09 PM UTC"}}
<= 2018-09-30 21:09:09 +0000 UTC

=> {{parseTime "Mon Aug 10 15:44:11 UTC+0100 2015"}}
<= 2015-08-10 15:44:11 +0000 UTC

=> {{parseTime "Thu, 4 Jan 2018 17:53:36 +0000"}}
<= 2018-01-04 17:53:36 +0000 UTC

=> {{parseTime "Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)"}}
<= 2015-07-03 18:04:07 +0100 GMT

=> {{parseTime "Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)"}}
<= 2021-01-03 00:12:23 +0800 +0800

=> {{parseTime "September 17, 2012 10:09am"}}
<= 2012-09-17 10:09:00 +0000 UTC

=> {{parseTime "September 17, 2012 at 10:09am PST-08"}}
<= 2012-09-17 10:09:00 -0800 PST

=> {{parseTime "September 17, 2012, 10:10:09"}}
<= 2012-09-17 10:10:09 +0000 UTC

=> {{parseTime "October 7, 1970"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "October 7th, 1970"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "12 Feb 2006, 19:17"}}
<= 2006-02-12 19:17:00 +0000 UTC

=> {{parseTime "12 Feb 2006 19:17"}}
<= 2006-02-12 19:17:00 +0000 UTC

=> {{parseTime "14 May 2019 19:11:40.164"}}
<= 2019-05-14 19:11:40.164 +0000 UTC

=> {{parseTime "7 oct 70"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "7 oct 1970"}}
<= 1970-10-07 00:00:00 +0000 UTC

=> {{parseTime "03 February 2013"}}
<= 2013-02-03 00:00:00 +0000 UTC

=> {{parseTime "1 July 2013"}}
<= 2013-07-01 00:00:00 +0000 UTC

=> {{parseTime "2013-Feb-03"}}
<= 2013-02-03 00:00:00 +0000 UTC

=> {{parseTime "06/Jan/2008:15:04:05 -0700"}}
<= 2008-01-06 15:04:05 -0700 -0700

=> {{parseTime "06/Jan/2008 15:04:05 -0700"}}
<= 2008-01-06 15:04:05 -0700 -0700

=> {{parseTime "3/31/2014"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "03/31/2014"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "08/21/71"}}
<= 1971-08-21 00:00:00 +0000 UTC

=> {{parseTime "8/1/71"}}
<= 1971-08-01 00:00:00 +0000 UTC

=> {{parseTime "4/8/2014 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "04/08/2014 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "4/8/14 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "04/2/2014 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "8/8/1965 12:00:00 AM"}}
<= 1965-08-08 00:00:00 +0000 UTC

=> {{parseTime "8/8/1965 01:00:01 PM"}}
<= 1965-08-08 13:00:01 +0000 UTC

=> {{parseTime "8/8/1965 01:00 PM"}}
<= 1965-08-08 13:00:00 +0000 UTC

=> {{parseTime "8/8/1965 1:00 PM"}}
<= 1965-08-08 13:00:00 +0000 UTC

=> {{parseTime "8/8/1965 12:00 AM"}}
<= 1965-08-08 00:00:00 +0000 UTC

=> {{parseTime "4/02/2014 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "03/19/2012 10:11:59"}}
<= 2012-03-19 10:11:59 +0000 UTC

=> {{parseTime "03/19/2012 10:11:59.3186369"}}
<= 2012-03-19 10:11:59.3186369 +0000 UTC

=> {{parseTime "2014/3/31"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "2014/03/31"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "2014/4/8 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "2014/04/08 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "2014/04/2 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "2014/4/02 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "2012/03/19 10:11:59"}}
<= 2012-03-19 10:11:59 +0000 UTC

=> {{parseTime "2012/03/19 10:11:59.3186369"}}
<= 2012-03-19 10:11:59.3186369 +0000 UTC

=> {{parseTime "2014:3:31"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "2014:03:31"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "2014:4:8 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "2014:04:08 22:05"}}
<= 2014-04-08 22:05:00 +0000 UTC

=> {{parseTime "2014:04:2 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "2014:4:02 03:00:51"}}
<= 2014-04-02 03:00:51 +0000 UTC

=> {{parseTime "2012:03:19 10:11:59"}}
<= 2012-03-19 10:11:59 +0000 UTC

=> {{parseTime "2012:03:19 10:11:59.3186369"}}
<= 2012-03-19 10:11:59.3186369 +0000 UTC

=> {{parseTime "2014年04月08日"}}
<= 2014-04-08 00:00:00 +0000 UTC

=> {{parseTime "2006-01-02T15:04:05+0000"}}
<= 2006-01-02 15:04:05 +0000 UTC

=> {{parseTime "2009-08-12T22:15:09-07:00"}}
<= 2009-08-12 22:15:09 -0700 -0700

=> {{parseTime "2009-08-12T22:15:09"}}
<= 2009-08-12 22:15:09 +0000 UTC

=> {{parseTime "2009-08-12T22:15:09.988"}}
<= 2009-08-12 22:15:09.988 +0000 UTC

=> {{parseTime "2009-08-12T22:15:09Z"}}
<= 2009-08-12 22:15:09 +0000 UTC

=> {{parseTime "2017-07-19T03:21:51:897+0100"}}
<= 2017-07-19 03:21:51.897 +0100 +0100

=> {{parseTime "2019-05-29T08:41-04"}}
<= 2019-05-29 08:41:00 -0400 -0400

=> {{parseTime "2014-04-26 17:24:37.3186369"}}
<= 2014-04-26 17:24:37.3186369 +0000 UTC

=> {{parseTime "2012-08-03 18:31:59.257000000"}}
<= 2012-08-03 18:31:59.257 +0000 UTC

=> {{parseTime "2014-04-26 17:24:37.123"}}
<= 2014-04-26 17:24:37.123 +0000 UTC

=> {{parseTime "2013-04-01 22:43"}}
<= 2013-04-01 22:43:00 +0000 UTC

=> {{parseTime "2013-04-01 22:43:22"}}
<= 2013-04-01 22:43:22 +0000 UTC

=> {{parseTime "2014-12-16 06:20:00 UTC"}}
<= 2014-12-16 06:20:00 +0000 UTC

=> {{parseTime "2014-12-16 06:20:00 GMT"}}
<= 2014-12-16 06:20:00 +0000 UTC

=> {{parseTime "2014-04-26 05:24:37 PM"}}
<= 2014-04-26 17:24:37 +0000 UTC

=> {{parseTime "2014-04-26 13:13:43 +0800"}}
<= 2014-04-26 13:13:43 +0800 +0800

=> {{parseTime "2014-04-26 13:13:43 +0800 +08"}}
<= 2014-04-26 13:13:43 +0800 +0800

=> {{parseTime "2014-04-26 13:13:44 +09:00"}}
<= 2014-04-26 13:13:44 +0900 +0900

=> {{parseTime "2012-08-03 18:31:59.257000000 +0000 UTC"}}
<= 2012-08-03 18:31:59.257 +0000 UTC

=> {{parseTime "2015-09-30 18:48:56.35272715 +0000 UTC"}}
<= 2015-09-30 18:48:56.35272715 +0000 UTC

=> {{parseTime "2015-02-18 00:12:00 +0000 GMT"}}
<= 2015-02-18 00:12:00 +0000 UTC

=> {{parseTime "2015-02-18 00:12:00 +0000 UTC"}}
<= 2015-02-18 00:12:00 +0000 UTC

=> {{parseTime "2015-02-08 03:02:00 +0300 MSK m=+0.000000001"}}
<= 2015-02-08 03:02:00 +0300 +0300

=> {{parseTime "2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001"}}
<= 2015-02-08 03:02:00.001 +0300 +0300

=> {{parseTime "2017-07-19 03:21:51+00:00"}}
<= 2017-07-19 03:21:51 +0000 UTC

=> {{parseTime "2014-04-26"}}
<= 2014-04-26 00:00:00 +0000 UTC

=> {{parseTime "2014-04"}}
<= 2014-04-01 00:00:00 +0000 UTC

=> {{parseTime "2014"}}
<= 2014-01-01 00:00:00 +0000 UTC

=> {{parseTime "2014-05-11 08:20:13,787"}}
<= 2014-05-11 08:20:13.787 +0000 UTC

=> {{parseTime "2020-07-20+08:00"}}
<= 2020-07-20 00:00:00 +0800 +0800

=> {{parseTime "3.31.2014"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "03.31.2014"}}
<= 2014-03-31 00:00:00 +0000 UTC

=> {{parseTime "08.21.71"}}
<= 1971-08-21 00:00:00 +0000 UTC

=> {{parseTime "2014.03"}}
<= 2014-03-01 00:00:00 +0000 UTC

=> {{parseTime "2014.03.30"}}
<= 2014-03-30 00:00:00 +0000 UTC

=> {{parseTime "20140601"}}
<= 2014-06-01 00:00:00 +0000 UTC

=> {{parseTime "20140722105203"}}
<= 2014-07-22 10:52:03 +0000 UTC

=> {{parseTime "171113 14:14:20"}}
<= 2017-11-13 14:14:20 +0000 UTC

=> {{parseTime "1332151919"}}
<= 2012-03-19 10:11:59 +0000 UTC

=> {{parseTime "1384216367189"}}
<= 2013-11-12 00:32:47.189 +0000 UTC

=> {{parseTime "1384216367111222"}}
<= 2013-11-12 00:32:47.111222 +0000 UTC

=> {{parseTime "1384216367111222333"}}
<= 2013-11-12 00:32:47.111222333 +0000 UTC

pow ^2.11.3

  • 介绍
    • 指数运算 an
    • 运算结果向 0 取整
  • 函数定义 func pow(a, n interface{}) int64
    • 参数
      1. a: interface{} 底数
      2. n: interface{} 指数
    • 返回值
      1. int64 向 0 取整后的指数运算结果 an
  • 参考
示例
text
=> {{pow 10 1}}
<= 10

=> {{pow 10.0 1.0}}
<= 10

=> {{pow "10" "1"}}
<= 10

=> {{pow "10.0" "1.0"}}
<= 10

=> {{pow 10 0.5}}
<= 3

=> {{pow 10 1.5}}
<= 31

=> {{powf 10 10}}
<= 10000000000

=> {{pow 0 10}}
<= 0

=> {{pow 10 0}}
<= 1

=> {{pow -10 1}}
<= -10

=> {{pow 10 -1}}
<= 0

=> {{pow -10 -1}}
<= 0

powf ^2.11.3

示例
text
=> {{powf 10 1}}
<= 10

=> {{powf 10.0 1.0}}
<= 10

=> {{powf "10" "1"}}
<= 10

=> {{powf "10.0" "1.0"}}
<= 10

=> {{powf 10 0.5}}
<= 3.1622776601683795

=> {{powf 10 1.5}}
<= 31.622776601683796

=> {{powf 10 10}}
<= 1e+10

=> {{powf 0 10}}
<= 0

=> {{powf 10 0}}
<= 1

=> {{powf -10 1}}
<= -10

=> {{powf 10 -1}}
<= 0.1

=> {{powf -10 -1}}
<= -0.1